Guides › INNER JOIN

INNER JOIN in SQL Server: names instead of IDs

An INNER JOIN keeps a row only when both tables have a match. That is how you turn a customer_id into a name.

Orders with the customer’s name

SELECT o.order_id, o.order_date, o.total_amount,
       c.first_name, c.last_name
FROM Orders o
INNER JOIN Customers c ON c.customer_id = o.customer_id
ORDER BY o.order_date DESC;

Read ON as “this row belongs to that row”. INNER is optional. JOIN means the same thing.

A customer with no orders vanishes

INNER JOIN drops them. If you need everyone, even people who never bought, that is a LEFT JOIN.

Try it on Harbour & Co

James Rowe (Sales Manager) needs this now: “Can you resend last week’s orders with the customer’s name instead of their ID? Newest first.” Write the query, run it, send the results. Free.

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