Select NAME, D.DEPTNO, DEPTNAME FROM EMP E, DEPT D WHERE E.DEPTNO = D.DEPTNO
SELECT field1, field2, field3 FROM first_table INNER JOIN second_table ON first_table.keyfield = second_table.foreign_keyfield
first_table
and the matching rows from second_table
.first_table
without a match in second_table
will still appear, but fields from second_table
will be NULL
for those rows.SELECT field1, field2, field3 FROM first_table LEFT OUTER JOIN second_table ON first_table.keyfield = second_table.foreign_keyfield;
second_table
and the matching rows from first_table
.second_table
without a match in first_table
will still appear, but fields from first_table
will be NULL
for those rows.SELECT field1, field2, field3 FROM first_table RIGHT OUTER JOIN second_table ON first_table.keyfield = second_table.foreign_keyfield;
first_table
and second_table
.NULL
in the corresponding columns.SELECT field1, field2, field3 FROM first_table FULL OUTER JOIN second_table ON first_table.keyfield = second_table.foreign_keyfield;
SELECT * FROM A INNER JOIN B ON A.SID=B.SID
A = Plumbers, B = ElectriciansNow if you wish to write a query which enlists all the plumbers and also those electricians which are plumbers, you will need a Left Outer Join.
SELECT A.NAME, B.NAME FROM A LEFT JOIN B ON A.SID=B.SID