0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
Rishabh Gupta
last month
Rishabhcountry asked

Respected Sir, I’m confused why this query returns 3 instead of 2. Shouldn’t the COUNT(DISTINCT brand) give just 2? SELECT COUNT(DISTINCT brand) AS distinct_product FROM Products WHERE brand = 'ByteCore' OR brand = 'ZapTech';

Abhay Jajodia
Expert
2 days ago
Abhay Jajodia answered

Hi Rishabh,

Good question — I see where the confusion is coming from.

Your query is counting how many distinct brands exist in the filtered data. Since you're filtering for ByteCore and ZapTech, there are clearly two distinct brands. So COUNT(DISTINCT brand) should return 2 — and it does.

But if you're getting 3 as the result, then the issue might be that you’re actually counting distinct product names, not brands.

If your intention is to count unique products under those brands, you should change the query to this:

SELECT COUNT(DISTINCT name) AS distinct_product  
FROM Products  
WHERE brand = 'ByteCore' OR brand = 'ZapTech';

This will count the number of different product names from those two brands — for example: keyboard, mouse, and headphone — which would give you 3.

So check what exactly you’re trying to count: brands or product names. That makes all the difference.

If you have more questions, I’m here to help.

SQL
This question was asked as part of the Learn SQL Basics course.