Page 1 of 1

How do you SELECT *, when you want to select DISTINCT?

Posted: Fri May 21, 2010 11:05 am
by simonmlewis
$result = mysql_query ("SELECT *, DISTINCT category FROM products WHERE pause = 'off' ORDER BY category ASC");

This doesn't work. And most SQL wizards here will probably see why.
I need to select everything from the row, where the DISTINCT query products a result.

ie, if there are 5 results (out of 50 rows for ex.), it has has all fields from it.

Re: How do you SELECT *, when you want to select DISTINCT?

Posted: Fri May 21, 2010 11:11 am
by Eran
DISTINCT selects distinct values in a group, not distinct rows. You need to use GROUP BY with some additional filtering