selecting distinct multiple columns..is that possible ?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

selecting distinct multiple columns..is that possible ?

Post by dibyendrah »

I want to select distinct muliple columns. select distinct(col1, col2) is not possible. Is it possible ?
Last edited by dibyendrah on Thu May 25, 2006 5:06 am, edited 1 time in total.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

I've never seen it done before. If ever I need to do this, I concatenate the column values, and select distinct on this value.

Might be a performance issue, depending on which columns they are.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

I need to select distinct rows having multiple fields. I'm banging my head to get the solution.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Is there no way you can do SELECT DISTINCT CONCAT(col1, col2, col3...) ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Distinct ALWAYS applies to ALL the columns in the SELECT clause... Thus not only the first immediately after it...

To me it appears as if you should GROUP BY col1, col2 in order to get the result that you want...
Post Reply