Sobes.tech
Junior — Middle

Can you explain the differences between inner join and left join in SQL?

sobes.tech AI

Answer from AI

Inner Join returns only those rows that have matches in both tables based on the join condition. If there is no corresponding record in one of the tables, such a row will not appear in the result.

Left Join returns all rows from the left table and the matching rows from the right table. If there is no match for a row from the left table, the result will include the values from the left table and NULL for the right table.

Example:

SELECT a.id, a.name, b.order_id
FROM customers a
INNER JOIN orders b ON a.id = b.customer_id;

Returns only customers who have orders.

SELECT a.id, a.name, b.order_id
FROM customers a
LEFT JOIN orders b ON a.id = b.customer_id;

Returns all customers, including those without orders (in this case, order_id will be NULL).

Can you explain the differences between inner join… - sobes.tech