Databases 4 min read

Understanding SQL JOIN Types: INNER, LEFT, RIGHT, FULL OUTER and Their Exclusive Variants

This article explains the seven common SQL JOIN variations—including INNER, LEFT, RIGHT, FULL OUTER, and their exclusive forms—illustrated with diagrams and complete SELECT statements, helping readers understand how each join type combines rows from two tables based on key relationships.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Understanding SQL JOIN Types: INNER, LEFT, RIGHT, FULL OUTER and Their Exclusive Variants

This guide presents seven SQL JOIN patterns, showing how each combines rows from two tables based on matching keys. Diagrams illustrate the logical result sets, and example SELECT statements demonstrate the exact syntax.

1. INNER JOIN (Inner Join)

Returns only rows with matching keys in both tables.

SELECT <select_list>
FROM Table_A A
INNER JOIN Table_B B
ON A.Key = B.Key

2. LEFT JOIN (Left Join)

Returns all rows from the left table and matching rows from the right table; non‑matching right rows appear as NULL.

SELECT <select_list>
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key

3. RIGHT JOIN (Right Join)

Returns all rows from the right table and matching rows from the left table; non‑matching left rows appear as NULL.

SELECT <select_list>
FROM Table_A A
RIGHT JOIN Table_B B
ON A.Key = B.Key

4. FULL OUTER JOIN (Outer Join)

Returns all rows when there is a match in either left or right table; unmatched rows contain NULLs for the opposite side.

SELECT <select_list>
FROM Table_A A
FULL OUTER JOIN Table_B B
ON A.Key = B.Key

5. LEFT JOIN EXCLUDING INNER JOIN (Left Anti‑Join)

Returns rows from the left table that have no matching key in the right table.

SELECT <select_list>
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key
WHERE B.Key IS NULL

6. RIGHT JOIN EXCLUDING INNER JOIN (Right Anti‑Join)

Returns rows from the right table that have no matching key in the left table.

SELECT <select_list>
FROM Table_A A
RIGHT JOIN Table_B B
ON A.Key = B.Key
WHERE A.Key IS NULL

7. FULL OUTER JOIN EXCLUDING INNER JOIN (Full Anti‑Join)

Returns rows that exist in either table but not in both.

SELECT <select_list>
FROM Table_A A
FULL OUTER JOIN Table_B B
ON A.Key = B.Key
WHERE A.Key IS NULL OR B.Key IS NULL

These examples, accompanied by visual diagrams, help developers choose the appropriate join for their query requirements.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackenddatabaseJOINTutorialquery
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.