DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

SQL: JOIN

Learn JOIN in SQL with practical examples.

Read time: 1 min Words: 46
Open Playground → SQL My Progress

SQL — JOIN

Overview

JOIN combines rows from two tables using a related key.

What you'll learn

  • INNER JOIN
  • LEFT JOIN
  • ON condition
  • table aliases

Syntax

SELECT ... FROM a JOIN b ON a.id=b.a_id;

Example

SELECT u.name, o.total
FROM users u
JOIN orders o ON o.user_id = u.id
ORDER BY o.total DESC;

Notes

  • Index join keys for speed.
  • LEFT JOIN keeps rows from the left table.

    Try: Open the Playground: /en/playground/sql