100% found this document useful (1 vote)
732 views1 page

VennDiagram1 PDF

This document describes different types of SQL joins, including inner joins, left outer joins, right outer joins, full outer joins, semi joins, anti semi joins, and cross joins. It provides examples of SQL queries using each type of join and illustrates the relationships between tables in each example using diagrams.

Uploaded by

ajaygupta.af3919
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
100% found this document useful (1 vote)
732 views1 page

VennDiagram1 PDF

This document describes different types of SQL joins, including inner joins, left outer joins, right outer joins, full outer joins, semi joins, anti semi joins, and cross joins. It provides examples of SQL queries using each type of join and illustrates the relationships between tables in each example using diagrams.

Uploaded by

ajaygupta.af3919
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

TSQL JOIN TYPES

Created by Steve Stedman


SELECT * SELECT *
FROM Table_1; FROM Table_1 t1
INNER JOIN Table_2 t2
Table 1 Table 2 SELECT * Table 1 Table 2 ON t1.id = t2.fk;
FROM Table_2;

INNER JOIN
SELECT from two tables

SELECT * SELECT *
FROM Table_1 t1 FROM Table_1 t1
LEFT JOIN Table_2 t2 RIGHT JOIN Table_2 t2
Table 1 Table 2 ON t1.id = t2.fk; Table 1 Table 2 ON t1.id = t2.fk;

LEFT OUTER JOIN RIGHT OUTER JOIN

SELECT * SELECT *
FROM Table_1 t1 FROM Table_1 t1
WHERE EXISTS (SELECT 1 Table 1 Table 2 WHERE NOT EXISTS (SELECT 1
Table 1 Table 2 FROM Table_2 t2 FROM Table_2 t2
WHERE t2.id = t1.fk WHERE t2.id = t1.fk
); );

SEMI JOIN Similar to INNER JOIN, with less duplication from Table 2. ANTI SEMI JOIN

SELECT * SELECT *
FROM Table_1 t1 FROM Table_1 t1
LEFT JOIN Table_2 t2 RIGHT JOIN Table_2 t2
Table 1 Table 2 ON t1.id = t2.fk Table 1 Table 2 ON t1.id = t2.fk
WHERE t2.fk is null; WHERE t1.id is null;

LEFT OUTER JOIN with exclusion RIGHT OUTER JOIN with exclusion
replacement for a NOT IN replacement for a NOT IN

SELECT * SELECT *
FROM Table_1 t1 FROM Table_1 t1
FULL OUTER JOIN Table_2 t2 CROSS JOIN Table_2 t2;
Table 1 Table 2 ON t1.id = t2.fk; Table 1 Table 2

FULL OUTER JOIN CROSS JOIN, like a FULL OUTER JOIN with out specifying JOIN condition.

SELECT * SELECT *
FROM Table_1 t1 Table 3 FROM Table_1 t1
FULL OUTER JOIN Table_2 t2 INNER JOIN Table_2 t2
Table 1 Table 2
ON t1.id = t2.fk ON t1.id = t2.fk
WHERE t1.id is null INNER JOIN Table_3 t3
Table 1 Table 2
OR t2.fk is null; ON t1.id = t3.fk;

FULL OUTER JOIN with exclusion replacement for a double NOT IN


Two INNER JOINs

SELECT * SELECT *
Table 3 FROM Table_1 t1 Table 3 FROM Table_1 t1
FULL OUTER JOIN Table_2 t2 INNER JOIN Table_2 t2
ON t1.id = t2.fk ON t1.id = t2.fk
FULL OUTER JOIN Table_3 t3 LEFT OUTER JOIN Table_3 t3
Table 1 Table 2 ON t1.id = t3.fk; Table 1 Table 2 ON t1.id = t3.fk;

Two FULL OUTER JOINS INNER JOIN and a LEFT OUTER JOIN

SELECT *
Table 3 FROM Table_1 t1
LEFT JOIN Table_2 t2
ON t1.id = t2.fk
LEFT JOIN Table_3 t3
Table 1 Table 2 ON t1.id = t3.fk;

Two LEFT OUTER JOINS

Created By Steve Stedman http://SteveStedman.com Twitter @SqlEmt

You might also like