Oracle Database Certified Associate (OCA) 1 minute read

Selain inner join, natural join dan outter join ada juga self join yaitu merelasikan ke tabel dirinya sendiri, berikut ilustrasinya:

gambar self join

Contoh kasusnya, saya ingin mencari semua karyawan dan berserta nama managernya. Berikut querynya:

Berikut hasilnya:

KODE_KARYAWAN NAMA_KARYAWAN                                  KODE_MANAGER NAMA_MANAGER
------------- ---------------------------------------------- ------------ ----------------------------------------------
          201 Michael Hartstein                                       100 Steven King
          101 Neena Kochhar                                           100 Steven King
          102 Lex De Haan                                             100 Steven King
          114 Den Raphaely                                            100 Steven King
          120 Matthew Weiss                                           100 Steven King
          121 Adam Fripp                                              100 Steven King
          122 Payam Kaufling                                          100 Steven King
          123 Shanta Vollman                                          100 Steven King
          124 Kevin Mourgos                                           100 Steven King
          145 John Russell                                            100 Steven King
          146 Karen Partners                                          100 Steven King
          147 Alberto Errazuriz                                       100 Steven King
          148 Gerald Cambrault                                        100 Steven King
          149 Eleni Zlotkey                                           100 Steven King
          200 Jennifer Whalen                                         101 Neena Kochhar
          203 Susan Mavris                                            101 Neena Kochhar
          204 Hermann Baer                                            101 Neena Kochhar
          205 Shelley Higgins                                         101 Neena Kochhar
          108 Nancy Greenberg                                         101 Neena Kochhar
          103 Alexander Hunold                                        102 Lex De Haan
          104 Bruce Ernst                                             103 Alexander Hunold
          105 David Austin                                            103 Alexander Hunold
          106 Valli Pataballa                                         103 Alexander Hunold
          107 Diana Lorentz                                           103 Alexander Hunold

107 rows selected.