T-SQL reference › DISTINCT

SELECT DISTINCT in SQL Server

DISTINCT removes duplicate rows from the result. It is a quick “which statuses exist.” It is a poor way to write a real report that also needs totals.

Which statuses

SELECT DISTINCT status
FROM Orders
ORDER BY status;

How many of each

SELECT status, COUNT(*) AS orders
FROM Orders
GROUP BY status;

That second query is what people meant. DISTINCT would hide the count.

Try it on Harbour & Co

Amy Nair (Finance Lead) needs this now: “Three numbers for shipped orders, all time: how many, total revenue, average order.” 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