← All references

JOIN

INNER JOIN / LEFT JOIN / RIGHT JOIN

Combine rows from two tables.

JOIN

Combines rows from two tables based on a related column.

Types

  • INNER JOIN — only matching rows from both.
  • LEFT JOIN — all left + matching right.
  • RIGHT JOIN — all right + matching left.
  • FULL OUTER JOIN — all from both.

``sql\nSELECT u.name, o.total\nFROM users u\nINNER JOIN orders o ON u.id = o.user_id;\n``

Example

SELECT u.name, o.total, o.status\nFROM users u\nINNER JOIN orders o ON u.id = o.user_id\nWHERE o.status = 'delivered'\nORDER BY o.total DESC;