View Full Version : SQL simple question
cl333r
March 28th, 2009, 07:51 PM
Hi folks,
Can't figure out how to google for such a question, a link or example would be much appreciated.
Say I have a table with a column 'colors' (like yellow, green,..).
How do I write an SQL query to get the list of different colors in that table?
Say there are 5 rows: yellow, yellow, green, green, blue
so that the request returns: yellow, green, blue
miken79
March 28th, 2009, 07:54 PM
select distinct colors from table.
simeon87
March 28th, 2009, 07:54 PM
Use SELECT DISTINCT: http://www.w3schools.com/sql/sql_distinct.asp
riksweeney
March 28th, 2009, 07:55 PM
Hi folks,
Can't figure out how to google for such a question, a link or example would be much appreciated.
Say I have a table with a column 'colors' (like yellow, green,..).
How do I write an SQL query to get the list of different colors in that table?
Say there are 5 rows: yellow, yellow, green, green, blue
so that the request returns: yellow, green, blue
SELECT DISTINCT COLORS
FROM COLOR_TABLE
This will select all the unique values from the COLORS column in the COLOR_TABLE table.
davec64
March 28th, 2009, 07:59 PM
It all depends which SQL you are using MSSQL, MYSQL, PLSQL (Oracle) etc.
As far as I know all the above are correct unles you are using MSSQL which would be:
Select Distinct (Colors)
From Colors_Table
It has the addition of brackets around the column name.
cl333r
March 28th, 2009, 08:08 PM
Wow! thanks a lot to all of you!
s1ightcrazed
March 28th, 2009, 10:41 PM
It all depends which SQL you are using MSSQL, MYSQL, PLSQL (Oracle) etc.
As far as I know all the above are correct unles you are using MSSQL which would be:
Select Distinct (Colors)
From Colors_Table
It has the addition of brackets around the column name.
Informix and possibly DB2 use Select Unique, unless my memory is mistaken.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.