Changes in How JOINs Are Written

If you read older SQL examples, you may see joins written in a way that looks quite different from modern tutorials. Both styles still work. This page explains what changed, roughly when, and why beginners are taught the newer style.

The older style: tables separated by commas

In older code you will often see tables listed with commas, and the matching rule placed in the WHERE clause:

SELECT students.name, courses.title
FROM students, enrolments, courses
WHERE students.id = enrolments.student_id
  AND courses.id = enrolments.course_id;

This works in every major database. The problem is that the rules for joining tables and the rules for filtering rows are mixed together in one place.

The newer style: explicit JOIN

The SQL-92 standard, published in 1992, introduced explicit join syntax. Today it is the style used in almost all tutorials and documentation:

SELECT students.name, courses.title
FROM students
JOIN enrolments ON students.id = enrolments.student_id
JOIN courses    ON courses.id  = enrolments.course_id;

Each JOIN comes with its own ON rule saying how the tables match. Any filtering goes separately in WHERE.

Why the newer style won

  1. Readability. You can see how each table connects at a glance.
  2. Fewer accidents. With commas, forgetting one matching condition silently produces every combination of rows (a "cross join"), which can be huge. With JOIN ... ON, a missing condition is much easier to spot, and many databases require the ON.
  3. Outer joins. LEFT JOIN and RIGHT JOIN keep rows that have no match. Older databases had their own special symbols for this, which differed between products. The standard syntax works the same everywhere.

Other observable changes

ChangeWhat it means for you
LEFT JOIN taught earlyBeginners learn to keep unmatched rows, not just matched ones
USING (column) shorthandSome tutorials join on same-named columns more briefly
Joins drawn as row matching, not just circlesTeaching has moved towards showing actual rows, which explains duplicates better
ORMs generate explicit joinsWhen you read SQL logged by an ORM, you will see JOIN syntax

FULL OUTER JOIN is part of the standard and supported by PostgreSQL and SQL Server. MySQL does not support it directly, and SQLite added it in version 3.39.0. Check your database's documentation.

What to do with older code

You do not need to rewrite working code just because it uses commas. But when you write new queries, use explicit JOIN ... ON. If you change an old query, converting it to the explicit style is a good way to understand it.

Try it

Take the comma version above, run it on a small practice database, then run the explicit version. You should get the same rows. Then remove one ON condition in each and compare what happens. Our step-by-step JOIN tutorial gives you tables to practise on.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.