Sales
ID customer_id order_date total_amount 1 C101 2022-01-15 1000 2 C102 2022-02-20 500 3 C103 2022-03-10 800 4 C101 2022-04-05 600
What is the result of the following query with respect to given relation 'Sales'?
SELECT COUNT(DISTINCT customer_id) FROM Sales;
Sales
| ID | customer_id | order_date | total_amount |
|---|---|---|---|
| 1 | C101 | 2022-01-15 | 1000 |
| 2 | C102 | 2022-02-20 | 500 |
| 3 | C103 | 2022-03-10 | 800 |
| 4 | C101 | 2022-04-05 | 600 |
What is the result of the following query with respect to given relation 'Sales'?
SELECT COUNT(DISTINCT customer_id) FROM Sales;
Solution
✅ Correct Option: 3
COUNT(DISTINCT customer_id) counts each different customer_id only once.
The customer_id values are C101, C102, C103 and C101. C101 appears twice, so the distinct values are C101, C102 and C103, which gives .
Option 4: this is the result of COUNT(customer_id) or COUNT(*), which counts all 4 rows including the repeated C101.
Related questions:
2025: 13 May Shift 2
2025: 16 May Shift 1
2025: 15 May Shift 2