Sobes.tech
Middle

Mis vahe on LEFT JOIN ja INNER JOIN vahel?

sobes.tech AI

Vastus AI-lt

INNER JOIN returns only the rows that have matching values in both tables. If there is no corresponding record in one of the tables, that row will not be included in the result.

LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table and the matching rows from the right table. If there is no match in the right table, the fields from the right table will be NULL in the result.

Example:

SELECT A.id, B.value
FROM A
INNER JOIN B ON A.id = B.a_id;

-- Returns only those ids from A that have a corresponding record in B

SELECT A.id, B.value
FROM A
LEFT JOIN B ON A.id = B.a_id;

-- Returns all ids from A, and for those without a match in B, value will be NULL