hojohappy
asked on
SQL Select Command to produce unique value list for all table columns
I need a MS SQL Select Command that will produce a unique set of values from multiple columns. This SQL Select command needs to read through all 25 columns of data and provide a list of only the unique values. For example:
TableA:
Col1 Col2 Col3 Col25
------ -------- -------- -------
Sugar Honey Wheat Milk
Wheat Sugar Corn Salt
Flour Corn Honey
Expected Result would be only the unqiue values from all columns:
Result
--------
Sugar
Wheat
Honey
Milk
Salt
Corn
Flour
TableA:
Col1 Col2 Col3 Col25
------ -------- -------- -------
Sugar Honey Wheat Milk
Wheat Sugar Corn Salt
Flour Corn Honey
Expected Result would be only the unqiue values from all columns:
Result
--------
Sugar
Wheat
Honey
Milk
Salt
Corn
Flour
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Guessing the above comments answered your question.
What is the logic for the sorting of your expected return set?
What is the logic for the sorting of your expected return set?
The CROSS APPLY method shown by IMSUKH should perform the best, by far.
http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx