Question:

Sales 

IDcustomer_idorder_datetotal_amount
1C1012022-01-151000
2C1022022-02-20500
3C1032022-03-10800
4C1012022-04-05600


What is the result of the following query with respect to the given relation 'Sales'? 

SELECT COUNT(DISTINCT customer_id) FROM Sales; 
 

Show Hint

COUNT(customer_id) counts all rows = 4.
COUNT(DISTINCT customer_id) counts unique entries = 3.
Always remove duplicates first when evaluating DISTINCT.
Updated On: Sep 8, 2026
  • 1
  • 2
  • 3
  • 4
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Concept:
The COUNT() aggregate function in SQL returns the number of values that match a specified condition.
When paired with the DISTINCT keyword, it eliminates duplicate entries before counting, computing the number of unique non-null values in that column.

Step 1: Identifying the Values in the Specified Column:

The column specified in the query is customer_id.
Extracting all entries from the Sales table for customer_id:
- Row 1: C101
- Row 2: C102
- Row 3: C103
- Row 4: C101

Step 2: Applying the DISTINCT Qualifier:

The DISTINCT keyword filters the extracted list so that only unique identifiers remain:
Unique values: \(\{ \text{C101}, \text{C102}, \text{C103} \}\).
Notice that the duplicate entry C101 is considered only once.

Step 3: Evaluating COUNT():

The COUNT function counts the elements in the unique set: \[ \text{Count} = 3 \] Final Answer:
The query returns 3. Therefore, option (C) is the correct answer.
Was this answer helpful?
0
0