For example, in a table, I have an attribute call "color", how to check what unique colors are included in the "color" attribute?
Name | Color |
---|---|
Alice | red |
Ben | blue |
Looking for a result that looks like: red, blue, green, black
Thanks in advance!
CodePudding user response:
Either you select the unique values of the column
select distinct color from yourtable
Or you group by the column
select color, count(*) as total
from yourtable
group by color
order by count(*) desc
CodePudding user response:
Use DISTINCT
to return only different values:
SELECT DISTINCT Color FROM table_name;