joins_SQL_cheat_sheet
joins_SQL_cheat_sheet
Joins
The CROSS JOIN is used to generate a paired combination of each row SELECT DEPT_ID_DEP, LOCT_ID FROM DEPARTMENTS CROSS JOIN
Cross Join SELECT column_name(s) FROM table1 CROSS JOIN table2;
of the first table with each row of the second table. LOCATIONS;
SELECT column_name(s) FROM table1 LEFT OUTER JOIN table2 ON The LEFT OUTER JOIN will return all records from the left side table select E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAME from EMPLOYEES AS
Left Outer Join table1.column_name = table2.column_name WHERE condition; and the matching records from the right table. E LEFT OUTER JOIN DEPARTMENTS AS D ON E.DEP_ID=D.DEPT_ID_DEP;
SELECT column_name(s) FROM table1 RIGHT OUTER JOIN table2 ON The RIGHT OUTER JOIN returns all records from the right table, and the select E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAME from EMPLOYEES AS
Right Outer Join table1.column_name = table2.column_name WHERE condition; matching records from the left table. E RIGHT OUTER JOIN DEPARTMENTS AS D ON E.DEP_ID=D.DEPT_ID_DEP;
The FULL OUTER JOIN clause results in the inclusion of rows from two
SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON select E.F_NAME,E.L_NAME,D.DEP_NAME from EMPLOYEES AS E FULL
Full Outer Join table1.column_name = table2.column_name WHERE condition;
tables. If a value is missing when rows are joined, that value is null in OUTER JOIN DEPARTMENTS AS D ON E.DEP_ID=D.DEPT_ID_DEP;
the result table.
SELECT column_name(s) FROM table1 T1, table1 T2 WHERE SELECT B.* FROM EMPLOYEES A JOIN EMPLOYEES B ON A.MANAGER_ID =
Self Join condition;
A self join is regular join but it can be used to joined with itself. B.MANAGER_ID WHERE A.EMP_ID = 'E1001';
The UNION operator is used to combine the result-set of two or more UNION
Full Outer Join SELECT column_name(s)
FROM table1 SELECT statements.
RIGHT OUTER JOIN table2 select E.F_NAME,E.L_NAME,D.DEP_NAME
ON table1.column_name = table2.column_name from EMPLOYEES AS E
WHERE condition RIGHT OUTER JOIN DEPARTMENTS AS D ON E.DEP_ID=D.DEPT_ID_DEP
Author(s)
D.M Naidu