How to select and join more than 2 tables in oracle?

52 views Asked by At

I have an oracle database design as shown in the picture. my question, how can i display id_produk of tb_produk by using select with condition :

produk_gaya.id_ghidup = wajah_gaya.id_ghidup
produk_konsern.id_konsern = wajah_konsern.id_konsern
produk_tipe.id_tipe = tb_wajah.id_tipe

Please help, thank you image of database design

1

There are 1 answers

3
MT0 On

You appear to just want to join the tables along the primary and foreign key relationships (you can skip tb_hidup as produk_gaya and wajah_gaya both have foreign-key relationship to the same primary key; similar for tb_konsern and tb_type):

SELECT p.id_produk
FROM   tb_produk p
       INNER JOIN produk_gaya pg    ON p.id_produk = pg.id_produk
       INNER JOIN wajah_gaya wg     ON pg.id_ghidup = wg.id_ghidup
       INNER JOIN produk_konsern pk ON p.id_produk = pk.id_produk
       INNER JOIN wajah_konsern wk  ON pk.id_konsern = wk.id_konsern
       INNER JOIN produk_tipe pt    ON p.id_produk = pt.id_produk
       INNER JOIN tb_wajah w        ON pt.id_tipe = tb_wajah.id_tipe