0% found this document useful (0 votes)
6 views

joins_SQL_cheat_sheet

Uploaded by

basurhiti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

joins_SQL_cheat_sheet

Uploaded by

basurhiti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL Cheat Sheet: JOIN statements

Joins

Topic Syntax Description Example

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 E.F_NAME,E.L_NAME, JH.START_DATE from EMPLOYEES as E


SELECT column_name(s) FROM table1 INNER JOIN table2 ON You can use an inner join in a SELECT statement to retrieve only
Inner Join INNER JOIN JOB_HISTORY as JH on E.EMP_ID=JH.EMPL_ID where
table1.column_name = table2.column_name; WHERE condition; the rows that satisfy the join conditions on every specified table. E.DEP_ID ='5';

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';

Joins in MySQL using phpMyAdmin

SELECT column_name(s) FROM table1 LEFT OUTER JOIN table2 ON


table1.column_name = table2.column_name WHERE condition
select E.F_NAME,E.L_NAME,D.DEP_NAME from EMPLOYEES AS E LEFT
UNION OUTER JOIN DEPARTMENTS AS D ON E.DEP_ID=D.DEPT_ID_DEP

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

You might also like