𝗝𝗼𝗶𝗻𝘀 𝗶𝗻 𝗦𝗤𝗟
SQL joins combine data from two or more tables. You use a related column to link them. This allows you to see information stored in different places.
Here are the main join types:
INNER JOIN This returns only rows with matching values in both tables. If a row in one table has no match in the other, it stays out.
LEFT JOIN This returns all rows from the left table. It also returns matching rows from the right table. If there is no match, the right side shows NULL.
RIGHT JOIN This returns all rows from the right table. It also returns matching rows from the left table. If there is no match, the left side shows NULL.
FULL OUTER JOIN This returns all rows when there is a match in either table. It shows everything from both sides. Unmatched rows show NULL.
CROSS JOIN This creates a combination of every row from the first table with every row from the second table. If you have 4 employees and 4 departments, you get 16 rows.
SELF JOIN This joins a table to itself. You use this to compare rows within the same table. For example, you use it to link an employee to their manager in one table.
Summary Guide:
• INNER JOIN: Matching rows only. • LEFT JOIN: All left rows plus matches. • RIGHT JOIN: All right rows plus matches. • FULL OUTER JOIN: All rows from both tables. • CROSS JOIN: Every possible combination. • SELF JOIN: A table joined with itself.