DEV Community

Rençber AKMAN
Rençber AKMAN

Posted on

🔍⭐What is a JOIN operation? What’s the difference between INNER JOIN and LEFT JOIN?

JOIN in SQL is used to combine data from multiple tables through a common column. This column is usually an id or a foreign key. The purpose is to display related data in a single result set.

📌 Example: Suppose there is a Customers table and an Orders table. To get the order information of a customer, we combine these two tables with a JOIN.

INNER JOIN 🔍

Brings only the records that match in both tables.

If there is no match, that row will not appear in the result.

Logic: Intersection set

Example: The list of customers who have placed an order.

LEFT JOIN ↔️

Brings all records from the left table. If there is no match in the right table, those columns will be NULL.

Logic: Entire left table + if right table exists, add extra data

Example: The list of all customers, with empty order information for those who have not placed any orders.

✅ Difference:

INNER JOIN → Only the matching ones ✅

LEFT JOIN → Entire left, add right if exists, otherwise empty 🗒️

💡 Tip: Unnecessary LEFT JOIN decreases performance. To find unmatched records, the technique

LEFT JOIN ... WHERE right_table.column IS NULL

is commonly used. On large datasets, using indexes speeds up the query.

Top comments (0)