Questions We Get Asked About JOINs

JOINs bring more beginner questions than any other part of SQL. These are the ones we receive most often, phrased the way they usually arrive. This is a set of reader-style questions, not an interview with a named person.

"What does a JOIN actually do?"

It puts rows from two tables side by side, wherever they match by a rule you give. If orders.customer_id matches customers.id, the order row and the customer row become one longer row in the result.

SELECT customers.name, orders.total
FROM orders
JOIN customers ON customers.id = orders.customer_id;

"What is the difference between JOIN and LEFT JOIN?"

JOIN (also called INNER JOIN) keeps only rows that match in both tables. LEFT JOIN keeps every row from the left table, and fills the right side with NULL where there is no match.

CustomerHas orders?Appears with JOIN?Appears with LEFT JOIN?
Customer AYesYesYes
Customer BNoNoYes, with NULL order columns

"Why did I get the same customer many times?"

Because the customer has many orders. Each matching order produces one result row. That is correct behaviour. If you want one row per customer, add GROUP BY and count or sum the orders.

"Why did I get a gigantic result?"

You probably forgot the ON condition, or wrote one that is always true. Without a matching rule, every row is paired with every other row. Ten customers and ten orders become a hundred rows.

"How do I join three tables?"

Add one join at a time, each with its own ON:

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

"What do the letters s, e and c mean?"

They are aliases: short nicknames for tables, set after the table name. They save typing and make it clear which table a column comes from.

"Are the Venn diagrams in tutorials accurate?"

They are a rough picture of which rows are kept, but they can mislead, because they do not show duplicate rows from one-to-many matches. Drawing the actual rows of two tiny tables and matching them by hand is often clearer.

"When should I use RIGHT JOIN?"

Rarely. A RIGHT JOIN is a LEFT JOIN with the tables swapped. Most people write LEFT JOIN and put the table they want to keep first, because it reads more naturally.

"Should I put conditions in ON or in WHERE?"

For inner joins, it gives the same result. For left joins it matters: a condition on the right table in WHERE removes the unmatched rows you were trying to keep. Put such conditions in ON instead.

Where to practise

Our step-by-step INNER and LEFT JOIN tutorial uses tables small enough to check by hand, and the session notes on LEFT JOIN losing rows explain the ON versus WHERE trap in more detail.

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.

No jobs, member profiles or expert services are listed or offered on this site; this page is general information only.