MySQL: Get unique values across multiple columns in alphabetical order
Posted
by RuCh
on Stack Overflow
See other posts from Stack Overflow
or by RuCh
Published on 2010-05-10T07:26:05Z
Indexed on
2010/05/10
7:34 UTC
Read the original article
Hit count: 240
mysql
Hey everyone,
If my table looks like this:
id | colA | colB | colC
===========================
1 | red | blue | yellow
2 | orange | red | red
3 | orange | blue | cyan
What SELECT query do I run such that the results returned are:
blue, cyan, orange, red, yellow
Basically, I want to extract a collective list of distinct values across multiple columns and return them in alphabetical order.
I am not concerned with performance optimization, because the results are being parsed to an XML file that will serve as a cache (database is hardly updated). So even a dirty solution would be fine.
Thanks for any help!
© Stack Overflow or respective owner