SQL JOINs
Joın is used to combine data from multiple tables based on a related column.
1. INNER JOIN
Returns only the rows that match in both tables.
SELECT *
FROM table1
JOIN table2
ON table1.column = table2.column;Shows only customers who have placed an order.
2. LEFT JOIN
Returns all rows from the left table, and matching rows from the right table. If no match, returns NULL.
SELECT *
FROM table1
LEFT JOIN table2
ON table1.column = table2.column;Shows all customers, even those with no orders.
Get seyma akın’s stories in your inbox
Join Medium for free to get updates from this writer.
3. RIGHT JOIN
Returns all rows from the right table, and matching rows from the left table.
SELECT *
FROM table1
RIGHT JOIN table2
ON table1.column = table2.column;Shows all orders, even if no matching customer is found.
4. SELF JOIN
Joins a table to itself. Useful for comparing rows in the same table.
SELECT *
FROM table1 AS A
JOIN table1 AS B
ON A.column = B.column;Shows each employee with their manager (if they have one).
FULL JOIN
Returns all rows from both tables.
If there’s a match, it combines the rows.
If there’s no match, it returns NULL for the missing side.
SELECT *
FROM table1
FULL JOIN table2
ON table1.column = table2.column;It is like combining the results of both LEFT JOIN and RIGHT JOIN.


