SQL-4 SUB QUERY






1.Menampilkan tabel pegawai
Query
select *from tb_pegawai

hasil

2. Menampilkan tabel golongan
Query
select *from tb_golongan
Hasil

3. menampilkan tabel gapok tertinggi
Query
sub_select
SELECT * FROM tb_golongan

WHERE gapok = (  SELECT max(gapok) FROM tb_golongan)
Hasil


4. operator dintinct
Query
SELECT DISTINCT kd_golongan FROM tb_pegawai
Hasil

5. operator IN
Query
select kd_golongan,nm_golongan from tb_golongan
where kd_golongan in
(select distinct kd_golongan from tb_pegawai)
Hasil

6. operator EXISTS
Query
select kd_golongan from tb_golongan
where EXISTS (select*from tb_pegawai
                        where kd_golongan=tb_golongan.kd_golongan)
Hasil

6. operator all
Query
select nip,nama from tb_pegawai
where kd_golongan=ALL (select kd_golongan from tb_pegawai
                                    where kd_golongan='02')
Hasil
latihan
1.      select  tb_pegawai.NAMA,TB_GOLONGAN.GAPOK,
TB_GOLONGAN.KD_GOLONGAN
from tb_pegawai,TB_GOLONGAN
where GAPOK=(select MAX (gapok) from TB_GOLONGAN
WHERE tb_pegawai.KD_GOLONGAN='03')


2.      select tb_pegawai.NAMA,TB_GOLONGAN.
GAPOK,TB_GOLONGAN.KD_GOLONGAN
from tb_pegawai,TB_GOLONGAN
where GAPOK=(select MIN (gapok) from TB_GOLONGAN
WHERE tb_pegawai.KD_GOLONGAN='01')



3.      select tb_pegawai.NAMA,TB_DEPARTEMEN.nm_departemen
FROM TB_DEPARTEMEN, tb_pegawai
where TB_DEPARTEMEN.kd_departemen=tb_pegawai.kd_departemen

4.      select tb_pegawai.NAMA,KD_GOLONGAN
from tb_pegawai
where tb_pegawai.SEX='L'



Comments