abdfahim Posted July 19, 2007 Share Posted July 19, 2007 As I say, Is it possible to Select distinct value from different columns in a single statement? Like Select Distinct Column1, Column2, Column3 From Table (Well, I dont know whether there is a syntax like this !!!) Link to comment https://forums.phpfreaks.com/topic/60720-is-it-possible-to-select-distinct-value-from-different-columns/ Share on other sites More sharing options...
Illusion Posted July 19, 2007 Share Posted July 19, 2007 DISTINCT on three columns results all the records that have distinct combination of these there columns not the distinct values from the each column. Link to comment https://forums.phpfreaks.com/topic/60720-is-it-possible-to-select-distinct-value-from-different-columns/#findComment-302205 Share on other sites More sharing options...
pnj Posted July 19, 2007 Share Posted July 19, 2007 Something like this is closer: select distinct(col1) as a from table1 union select distinct(col2) as a from table2; But you could get a duplicate if the same data is in different columns. If this is the case, you could try a subquery: select distinct(a) from (select distinct(col1) as a from table1 union select distinct(col2) as a from table2) as foo cheers -pnj Link to comment https://forums.phpfreaks.com/topic/60720-is-it-possible-to-select-distinct-value-from-different-columns/#findComment-302284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.