0% found this document useful (0 votes)
15 views2 pages

SQL Cheat Sheet JOIN Statements

The document is a cheat sheet for SQL JOIN statements, detailing various types of joins including Cross Join, Inner Join, Left Outer Join, Right Outer Join, Full Outer Join, and Self Join, along with their syntax and examples. It also mentions the use of the UNION operator for combining results from multiple SELECT statements. The document was authored by D.M. Naidu and has an initial version dated October 4, 2022.

Uploaded by

datachamp121
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)
15 views2 pages

SQL Cheat Sheet JOIN Statements

The document is a cheat sheet for SQL JOIN statements, detailing various types of joins including Cross Join, Inner Join, Left Outer Join, Right Outer Join, Full Outer Join, and Self Join, along with their syntax and examples. It also mentions the use of the UNION operator for combining results from multiple SELECT statements. The document was authored by D.M. Naidu and has an initial version dated October 4, 2022.

Uploaded by

datachamp121
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/ 2

2/28/23, 10:35 PM https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-JOIN_Statements.md.html?

origin=…

SQL Cheat Sheet: JOIN statements

Joins
Topic Syntax Description Example

Cross Join SELECT column_name(s) FROM table1 The CROSS JOIN is used to generate a SELECT DEPT_ID_DEP, LOCT_ID FROM
CROSS JOIN table2; paired combination of each row of the DEPARTMENTS CROSS JOIN LOCATIONS;
first table with each row of the second
table.

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

Left Outer SELECT column_name(s) FROM table1 The LEFT OUTER JOIN will return all select
Join LEFT OUTER JOIN table2 ON records from the left side table and the E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAM
table1.column_name = matching records from the right table. E from EMPLOYEES AS E LEFT OUTER
table2.column_name WHERE condition; JOIN DEPARTMENTS AS D ON
E.DEP_ID=D.DEPT_ID_DEP;

Right SELECT column_name(s) FROM table1 The RIGHT OUTER JOIN returns all select
Outer Join RIGHT OUTER JOIN table2 ON records from the right table, and the E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAM
table1.column_name = matching records from the left table. E from EMPLOYEES AS E RIGHT OUTER
table2.column_name WHERE condition; JOIN DEPARTMENTS AS D ON
E.DEP_ID=D.DEPT_ID_DEP;

Full Outer SELECT column_name(s) FROM table1 The FULL OUTER JOIN clause results in select E.F_NAME,E.L_NAME,D.DEP_NAME
Join FULL OUTER JOIN table2 ON the inclusion of rows from two tables. from EMPLOYEES AS E FULL OUTER JOIN
table1.column_name = If a value is missing when rows are DEPARTMENTS AS D ON
table2.column_name WHERE condition; joined, that value is null in the result E.DEP_ID=D.DEPT_ID_DEP;
table.

Self Join SELECT column_name(s) FROM table1 A self join is regular join but it can be SELECT B.* FROM EMPLOYEES A JOIN
T1, table1 T2 WHERE condition; used to joined with itself. EMPLOYEES B ON A.MANAGER_ID =
B.MANAGER_ID WHERE A.EMP_ID =
'E1001';

Joins in MySQL using phpMyAdmin


Full Outer SELECT column_name(s) FROM table1 The UNION operator is used to combine select E.F_NAME,E.L_NAME,D.DEP_NAME
Join LEFT OUTER JOIN table2 ON the result-set of two or more SELECT from EMPLOYEES AS E LEFT OUTER JOIN
table1.column_name = statements. DEPARTMENTS AS D ON
table2.column_name WHERE condition E.DEP_ID=D.DEPT_ID_DEP
UNION UNION

SELECT column_name(s) FROM table1 select E.F_NAME,E.L_NAME,D.DEP_NAME


RIGHT OUTER JOIN table2 ON from EMPLOYEES AS E RIGHT OUTER JOIN
table1.column_name = DEPARTMENTS AS D ON
table2.column_name WHERE condition E.DEP_ID=D.DEPT_ID_DEP

https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-JOIN_Statements.md.html?origin=www.coursera.org 1/2
2/28/23, 10:35 PM https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-JOIN_Statements.md.html?origin=…

Author(s)
D.M Naidu

Changelog
Date Version Changed by Change Description

2022-10-04 1.0 D.M.Naidu Initial Version

https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DB0201EN-SkillsNetwork/labs/CheatSheet/SQL-Cheat-Sheet-JOIN_Statements.md.html?origin=www.coursera.org 2/2

You might also like