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
| OrderID | CustomerID | CustomerName | Amount |
|---|---|---|---|
| 101 | 1 | Aarav Traders | 245.5 |
| 102 | 4 | Delta Mart | 89.9 |
| 103 | 2 | Blue Harbor Foods | 412 |
| 104 | 1 | Aarav Traders | 56.25 |
| 105 | 5 | Evergreen Grocers | 150 |
| 106 | 3 | Cedar & Co | 320.75 |
| 107 | 4 | Delta Mart | 27 |
| 108 | 7 | Golden Spoon | 198.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
| OrderID | CustomerName | Amount |
|---|---|---|
| 101 | Aarav Traders | 245.5 |
| 103 | Blue Harbor Foods | 412 |
| 106 | Cedar & Co | 320.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 ... ONconditions. USINGis acceptable when you control the schema and names are stable.- Use
NATURAL JOINfor quick ad-hoc queries only.