SQL Joins

SQL Joins are used to retrieve data from multiple tables based on a related column that exists in both tables. This is particularly useful when data is normalized and spread across different tables, and you want to bring it together in a single query result.

SQL Joins Syntax

SELECT columns
FROM table1
JOIN table2
ON table1.common_column = table2.common_column;



SQL Joins Different Types of Joins

  • INNER JOIN – Returns only the rows that have matching values in both tables. If there is no match, the row won’t appear in the result.
  • LEFT JOIN (LEFT OUTER JOIN) – Returns all rows from the left table and the matched rows from the right table.
  • RIGHT JOIN (RIGHT OUTER JOIN) – Returns all rows from the right table and the matched rows from the left table. If there’s no match, the result is NULL for columns from the left table.
  • FULL JOIN (FULL OUTER JOIN) – Returns all rows when there is a macth in either left or right table. If there’s no match, NULL is shown for non-matching columns from either table.
  • SELF JOIN – Returns rows from the same table that are joined with itself, allowing for comparisons between different rows within that table.

SQL Joins Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top