Middle
What is the difference between LEFT JOIN and INNER JOIN?
sobes.tech AI
Answer from AI
INNER JOIN returns only the rows that have matching values in both tables. If there is no corresponding record in one of the tables, the 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 result will include rows with NULL in the right table's fields.
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