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

SQL Cheat Sheet JOIN Statements

This document is a SQL cheat sheet focused on JOIN statements, detailing various types of joins such as CROSS JOIN, INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN, and SELF JOIN, along with their syntax and examples. It also includes information on using the UNION operator to combine result sets from multiple SELECT statements. The author of the document is D.M Naidu.

Uploaded by

jass83082
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL Cheat Sheet JOIN Statements

This document is a SQL cheat sheet focused on JOIN statements, detailing various types of joins such as CROSS JOIN, INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN, and SELF JOIN, along with their syntax and examples. It also includes information on using the UNION operator to combine result sets from multiple SELECT statements. The author of the document is D.M Naidu.

Uploaded by

jass83082
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

7/24/24, 5:26 PM about:blank

SQL Cheat Sheet: JOIN statements

Joins

Topic Syntax Description Example


The CROSS JOIN is used to generate a paired
SELECT column_name(s) FROM table1 CROSS SELECT DEPT_ID_DEP, LOCT_ID FROM
Cross Join JOIN table2;
combination of each row of the first table with DEPARTMENTS CROSS JOIN LOCATIONS;
each row of the second table.
You can use an inner join in a SELECT select E.F_NAME,E.L_NAME, JH.START_DATE
SELECT column_name(s) FROM table1 INNER
from EMPLOYEES as E INNER JOIN JOB_HISTORY
Inner Join JOIN table2 ON table1.column_name = statement to retrieve only the rows that satisfy as JH on E.EMP_ID=JH.EMPL_ID where E.DEP_ID
table2.column_name; WHERE condition; the join conditions on every specified table. ='5';
The LEFT OUTER JOIN will return all records from select
SELECT column_name(s) FROM table1 LEFT
E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAME from
Left Outer Join OUTER JOIN table2 ON table1.column_name = the left side table and the matching records from EMPLOYEES AS E LEFT OUTER JOIN DEPARTMENTS
table2.column_name WHERE condition; the right table. AS D ON E.DEP_ID=D.DEPT_ID_DEP;
The RIGHT OUTER JOIN returns all records from select
Right Outer SELECT column_name(s) FROM table1 RIGHT
E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAME from
OUTER JOIN table2 ON table1.column_name = the right table, and the matching records from
Join table2.column_name WHERE condition;
EMPLOYEES AS E RIGHT OUTER JOIN DEPARTMENTS
the left table. AS D ON E.DEP_ID=D.DEPT_ID_DEP;
The FULL OUTER JOIN clause results in the
SELECT column_name(s) FROM table1 FULL inclusion of rows from two tables. If a value is select E.F_NAME,E.L_NAME,D.DEP_NAME from
Full Outer Join OUTER JOIN table2 ON table1.column_name = EMPLOYEES AS E FULL OUTER JOIN DEPARTMENTS
table2.column_name WHERE condition; missing when rows are joined, that value is null AS D ON E.DEP_ID=D.DEPT_ID_DEP;
in the result table.
SELECT column_name(s) FROM table1 T1, A self join is regular join but it can be used to SELECT B.* FROM EMPLOYEES A JOIN EMPLOYEES
Self Join B ON A.MANAGER_ID = B.MANAGER_ID WHERE
table1 T2 WHERE condition; joined with itself. A.EMP_ID = 'E1001';

Joins in MySQL using phpMyAdmin

SELECT column_name(s) FROM table1 LEFT


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

Author(s)
D.M Naidu

about:blank 1/2
7/24/24, 5:26 PM about:blank

about:blank 2/2

You might also like