Guides › RIGHT JOIN

RIGHT JOIN in SQL Server: almost nobody writes this at work

A RIGHT JOIN keeps every row from the right table. You will see it in textbooks. You will almost never see it in a shop that has to maintain the script next year.

What it does

SELECT c.customer_id, c.first_name, o.order_id, o.total_amount
FROM Customers c
RIGHT JOIN Orders o ON o.customer_id = c.customer_id;

Every order is kept. A customer with no orders does not appear. An order with a missing customer_id still appears, with NULL customer columns.

Write the LEFT instead

SELECT c.customer_id, c.first_name, o.order_id, o.total_amount
FROM Orders o
LEFT JOIN Customers c ON c.customer_id = o.customer_id;

Same result. The “main” table is on the left, which is how people read. New joiners look for LEFT JOIN. Reviewers look for LEFT JOIN.

Mixing LEFT and RIGHT in one query

It parses. Nobody can tell you what it means in six months. Pick a side, stay there. At Harbour & Co we only write INNER and LEFT.

So are they used?

Generated SQL, old Access upsizes, and people who learned from a slide that listed every join type. Not in a ticket you send to James.

Try it on Harbour & Co

Becky Ashworth (Support) needs this now: “Who signed up but never ordered? I want to send them a nudge.” Write the query, run it, send the results. On the paid plan.

Take the ticket →

Learn it on a real ticket

Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.

Clock in free See Monday’s tickets