T-SQL reference › EXISTS
EXISTS in SQL Server: “has at least one”
EXISTS asks whether a subquery finds a row. It does not care how many. That is the right shape for “customers who have ever cancelled.”
Has a cancelled order
SELECT c.customer_id, c.first_name, c.last_name
FROM Customers c
WHERE EXISTS (
SELECT 1 FROM Orders o
WHERE o.customer_id = c.customer_id
AND o.status = 'Cancelled'
);
SELECT 1 is a habit. EXISTS only checks for a row, not the value. A JOIN to cancelled orders can duplicate the customer if they cancelled twice.
Try it on Harbour & Co
Becky Ashworth (Support) needs this now: “Which customers have had at least one cancelled order? One row each, please.” 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