Junior — Middle
Kas saaksite loetleda PostgreSQL-is kasutatavaid tabelite ühendamise tüüpe?
sobes.tech AI
Vastus AI-lt
In PostgreSQL, the following main types of table joins (JOIN) are used:
- INNER JOIN — returns only the rows that match the join condition in both tables.
- LEFT JOIN (LEFT OUTER JOIN) — returns all rows from the left table and the matching rows from the right; if there are no matches, the right table fields will be NULL.
- RIGHT JOIN (RIGHT OUTER JOIN) — similar to LEFT JOIN, but for the right table.
- FULL JOIN (FULL OUTER JOIN) — returns all rows from both tables, filling with NULL where there are no matches.
- CROSS JOIN — Cartesian product of two tables, returning all possible row combinations.
Example query with INNER JOIN:
SELECT a.id, b.name
FROM table_a a
INNER JOIN table_b b ON a.b_id = b.id;