Sobes.tech
Middle

Mis vahe on LEFT JOIN ja INNER JOIN vahel

sobes.tech AI

Vastus AI-lt

LEFT JOIN and INNER JOIN are types of table joins in SQL, which differ in how they select rows:

  • INNER JOIN returns only the rows that have matches in both tables according to the join condition.
  • LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match, the columns from the right table will be NULL.

Example:

SELECT a.id, b.value
FROM table_a a
INNER JOIN table_b b ON a.id = b.a_id;

SELECT a.id, b.value
FROM table_a a
LEFT JOIN table_b b ON a.id = b.a_id;

In the first case, only records with matches in both tables are shown. In the second, all records from table_a are shown, even if there are no matching records in table_b.