0% found this document useful (0 votes)
30 views1 page

Joins

This document provides an overview of different types of JOIN statements that can be used in SQL including inner join, outer join, self join and union. It also provides syntax examples and descriptions of each JOIN type.

Uploaded by

itsmeil012024
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)
30 views1 page

Joins

This document provides an overview of different types of JOIN statements that can be used in SQL including inner join, outer join, self join and union. It also provides syntax examples and descriptions of each JOIN type.

Uploaded by

itsmeil012024
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

03/02/2024, 18:22 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
Inner Join JOIN table2 ON table1.column_name = statement to retrieve only the rows that satisfy JOB_HISTORY as JH on E.EMP_ID=JH.EMPL_ID
table2.column_name; WHERE condition; the join conditions on every specified table. where E.DEP_ID ='5';
select
SELECT column_name(s) FROM table1 LEFT The LEFT OUTER JOIN will return all records E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAME
Left Outer Join OUTER JOIN table2 ON table1.column_name from the left side table and the matching records from EMPLOYEES AS E LEFT OUTER JOIN
= table2.column_name WHERE condition; from the right table. DEPARTMENTS AS D ON
E.DEP_ID=D.DEPT_ID_DEP;
select
SELECT column_name(s) FROM table1 RIGHT The RIGHT OUTER JOIN returns all records from E.EMP_ID,E.L_NAME,E.DEP_ID,D.DEP_NAME
Right Outer
OUTER JOIN table2 ON table1.column_name the right table, and the matching records from from EMPLOYEES AS E RIGHT OUTER JOIN
Join = table2.column_name WHERE condition; DEPARTMENTS AS D ON
the left table.
E.DEP_ID=D.DEPT_ID_DEP;
The FULL OUTER JOIN clause results in the select E.F_NAME,E.L_NAME,D.DEP_NAME from
SELECT column_name(s) FROM table1 FULL inclusion of rows from two tables. If a value is EMPLOYEES AS E FULL OUTER JOIN
Full Outer Join OUTER JOIN table2 ON table1.column_name
missing when rows are joined, that value is null DEPARTMENTS AS D ON
= table2.column_name WHERE condition;
in the result table. E.DEP_ID=D.DEPT_ID_DEP;

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
Self Join EMPLOYEES B ON A.MANAGER_ID =
table1 T2 WHERE condition; 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 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
UNION E.DEP_ID=D.DEPT_ID_DEP
The UNION operator is used to combine the
Full Outer Join SELECT column_name(s) UNION
FROM table1 result-set of two or more SELECT statements.
RIGHT OUTER JOIN table2 select E.F_NAME,E.L_NAME,D.DEP_NAME
ON table1.column_name = from EMPLOYEES AS E
table2.column_name RIGHT OUTER JOIN DEPARTMENTS AS D ON
WHERE condition E.DEP_ID=D.DEPT_ID_DEP

Author(s)
D.M Naidu

Changelog
Date Version Changed by Change Description
2023-05-04 1.1 Benny Li Formatting changes
2022-10-04 1.0 D.M.Naidu Initial Version

about:blank 1/1

You might also like