+ 2

When to use this DISTINCT?

We can go for DISTINCT on any column in the table, when we want to know which all the possible values the field or column can hold. for ex., I have one table named DRESS. there are around 500 records, each one for one person. There is a column named COLOR, holding colors. A single person can wear any single colored tie. Now, to know how many colors we are dealing with and which are those colors, I can go with below query : SELECT DISTINCT(COLOR) FROM DRESS; how many rows returned- will give me the count.

10th Apr 2017, 8:07 AM
Gayatri C
Gayatri C - avatar
2 Answers
+ 5
Yes, that's correct â˜ș
10th Apr 2017, 8:10 AM
Shraddha
Shraddha - avatar
+ 2
SELECT COUNT(DISTINCT(COLOR)) FROM dress; This count the rows with only the distinct colors
10th Apr 2017, 8:55 AM
nextco
nextco - avatar