Excel → T-SQL › UNIQUE

Excel UNIQUE to SELECT DISTINCT / GROUP BY

A unique customer list is DISTINCT customer_id. If you need the count, GROUP BY.

SELECT DISTINCT customer_id FROM Orders;
SELECT customer_id, COUNT(*) AS n FROM Orders GROUP BY customer_id;

UNIQUE of two columns is DISTINCT col1, col2. Not two UNIQUEs.

Canonical translation

SELECT DISTINCT customer_id FROM Orders;
SELECT customer_id, COUNT(*) AS n FROM Orders GROUP BY customer_id;

Then write it on a ticket

Monday is free. A colleague asks, you type, we mark it.

Clock in free