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

VennDiagram2 PDF

This document describes different types of SQL JOINs: 1. INNER JOIN returns rows that have matching values in both tables. LEFT OUTER JOIN and RIGHT OUTER JOIN return all rows from the left/right table, and the matched rows from the right/left table respectively. 2. SEMI JOIN and ANTI SEMI JOIN are similar to INNER JOIN but return fewer duplicates. 3. LEFT OUTER JOIN with exclusion and RIGHT OUTER JOIN with exclusion add a WHERE clause to filter out rows with null values from the right/left table respectively. 4. FULL OUTER JOIN returns all rows from both tables by using a UNION of a LEFT OUTER JOIN and RIGHT OUTER

Uploaded by

Raghu Gowda
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)
127 views1 page

VennDiagram2 PDF

This document describes different types of SQL JOINs: 1. INNER JOIN returns rows that have matching values in both tables. LEFT OUTER JOIN and RIGHT OUTER JOIN return all rows from the left/right table, and the matched rows from the right/left table respectively. 2. SEMI JOIN and ANTI SEMI JOIN are similar to INNER JOIN but return fewer duplicates. 3. LEFT OUTER JOIN with exclusion and RIGHT OUTER JOIN with exclusion add a WHERE clause to filter out rows with null values from the right/left table respectively. 4. FULL OUTER JOIN returns all rows from both tables by using a UNION of a LEFT OUTER JOIN and RIGHT OUTER

Uploaded by

Raghu Gowda
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

MySQL JOIN Types

Created by Steve Stedman


SELECT * SELECT *
FROM Table1; FROM Table1 t1
Table 1 Table 2 Table 1 Table 2
INNER JOIN Table2 t2
SELECT * ON t1.fk = t2.id;
FROM Table2; INNER JOIN
SELECT from two tables

SELECT * SELECT *
FROM Table1 t1 FROM Table1 t1
Table 1 Table 2
LEFT OUTER JOIN Table2 t2 Table 1 Table 2 RIGHT OUTER JOIN Table2 t2
ON t1.fk = t2.id; ON t1.fk = t2.id;
LEFT OUTER JOIN RIGHT OUTER JOIN

SELECT * SELECT *
FROM Table1 t1 FROM Table1 t1
WHERE EXISTS (SELECT 1 Table 1 Table 2 WHERE NOT EXISTS (SELECT 1
Table 1 Table 2
FROM Table2 t2 FROM Table2 t2
WHERE t1.fk = t2.id WHERE t1.fk = t2.id
); );
SEMI JOIN – Similar to INNER JOIN, with less duplication. ANTI SEMI JOIN

SELECT * SELECT *
FROM Table1 t1 FROM Table1 t1
Table 1 Table 2 LEFT OUTER JOIN Table2 t2 Table 1 Table 2 RIGHT OUTER JOIN Table2 t2
ON t1.fk = t2.id ON t1.fk = t2.id
WHERE t2.id is null; WHERE t1.fk is null;
LEFT OUTER JOIN with exclusion RIGHT OUTER JOIN with exclusion

SELECT * FROM Table1 t1 SELECT * FROM Table1 t1


LEFT OUTER JOIN Table2 t2
LEFT OUTER JOIN Table2 t2
ON t1.fk = t2.id
ON t1.fk = t2.id Table 1 Table 2 WHERE t2.id IS NOT NULL
Table 1 Table 2
UNION UNION
SELECT * FROM Table1 t1 SELECT * FROM Table1 t1
RIGHT OUTER JOIN Table2 t2
RIGHT OUTER JOIN Table2 t2 FULL OUTER JOIN with
FULL OUTER JOIN ON t1.fk = t2.id;
ON t1.fk = t2.id
exclusion WHERE t1.ID IS NOT NULL;

SELECT * SELECT *
Table 3 Table 3
FROM Table1 t1 FROM Table1 t1
INNER JOIN Table2 t2 LEFT OUTER JOIN Table2 t2
Table 1 Table 2 ON t1.fk = t2.id Table 1 Table 2 ON t1.fk = t2.id
INNER JOIN Table3 t3 LEFT OUTER JOIN Table3 t3
ON t1.fk_table3 = t3.id; ON t1.fk_table3 = t3.id;
Two INNER JOINs Two LEFT OUTER JOINS

SELECT *
Table 3
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.fk = t2.id
Table 1 Table 2
LEFT OUTER JOIN Table3 t3
ON t1.fk_table3 = t3.id;
INNER JOIN and a LEFT OUTER JOIN

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy