Code & QA Zone: Tutorials, Tools, Guides & Tips for Developers & Testers

SQL JOINs Explained With Diagrams

Understanding SQL joins is one of the most important skills when working with relational databases. Instead of just reading definitions.

Join operations are essential in SQL to combine data from multiple tables. Understanding the differences between INNER, LEFT, RIGHT, and FULL OUTER JOINs can be tricky, but visual diagrams make it intuitive. In this post, we’ll go through each JOIN type with examples and visual aids.

Let’s look at visual diagrams to see how each join works:

1. INNER JOIN

INNER JOIN returns only rows that exist in both tables. If a row does not match in the other table, it is excluded.

Inner Join Diagram - Code & QA Zone

When to use

When you need only matching data between tables.

2. LEFT JOIN

LEFT JOIN returns all rows from the left table, even if there is no match in the right table. If there is no match, the missing values are filled with NULL:

Left Join Diagram - Code & QA Zone

When to use

When you want all records from the left table, regardless of matches.

3. RIGHT JOIN

RIGHT JOIN returns all rows from the right table, even if there is no match in the left table:

Right Join Diagram - Code & QA Zone

When to use

When you want all records from the right table, regardless of matches.

4. FULL OUTER JOIN

Definition: Returns all rows from both tables, matching where possible. Unmatched rows show NULL values.

Full Outer Join Diagram - Code & QA Zone

When to use

When you need all data from both tables, with or without matches.

Final Quick Tip

A useful way to remember the JOINs:

  • INNERIntersection between tables
  • LEFTAll left table rows + matches from right
  • RIGHTAll right table rows + matches from left
  • FULLEverything from both tables, NULL where no match exists

Happy learning and thank you for reading!