NATURAL JOIN

The SQL NATURAL JOIN

NATURAL JOIN joins two tables on all columns that have the same name in both, without an ON clause. The shared columns appear only once in the result.

SELECT column_name(s)
FROM table1
NATURAL JOIN table2;

Example

Example

Orders and Customers share only CustomerID, so this is an inner join on it:

SELECT OrderID, CustomerID, CustomerName, Amount
FROM Orders
NATURAL JOIN Customers
ORDER BY OrderID;

Result: 8 rows

OrderIDCustomerIDCustomerNameAmount
1011Aarav Traders245.5
1024Delta Mart89.9
1032Blue Harbor Foods412
1041Aarav Traders56.25
1055Evergreen Grocers150
1063Cedar & Co320.75
1074Delta Mart27
1087Golden Spoon198.4

Support

Supported by MySQL, PostgreSQL, Oracle and SQLite. SQL Server does not support NATURAL JOIN. There are also NATURAL LEFT JOIN and NATURAL RIGHT JOIN variants.

JOIN ... USING

USING (column) is a middle ground: you name the shared column explicitly, but do not repeat it on both sides. The column appears once in the result.

Example

Join Orders and Customers on CustomerID, written once:

SELECT OrderID, CustomerName, Amount
FROM Orders
JOIN Customers USING (CustomerID)
WHERE Amount > 200;

Result: 3 rows

OrderIDCustomerNameAmount
101Aarav Traders245.5
103Blue Harbor Foods412
106Cedar & Co320.75

Several Columns

SELECT *
FROM Enrollments
JOIN Grades USING (StudentID, CourseID);

Note: USING works in MySQL, PostgreSQL, Oracle and SQLite, but not SQL Server.

A Hidden Trap

A natural join depends on column names, which can change. Suppose both Orders and Customers later get a column called CreatedAt. Every natural join between them silently starts matching on CreatedAt too, and returns almost no rows. No error is raised.

Example

Simulate it: add a City column to Orders. Now the natural join matches on CustomerID and City:

ALTER TABLE Orders ADD COLUMN City VARCHAR(50);

SELECT COUNT(*) AS RowsReturned
FROM Orders
NATURAL JOIN Customers;

Result: 1 row

RowsReturned
0

Recommendation

  • In application code, always write explicit JOIN ... ON conditions.
  • USING is acceptable when you control the schema and names are stable.
  • Use NATURAL JOIN for quick ad-hoc queries only.