MySQL Forums
Forum List  »  Newbie

group by - order of omitted rows
Posted by: Jesse Sandberg
Date: July 26, 2005 02:27AM

Hello,

A small table to describe the problem
id arvo luku
1 eka 1
2 toka 1
3 kolmas 1

A query with a subquery which produces the result set I want
SELECT * FROM
(SELECT * FROM `test2` ORDER BY arvo = 'toka' DESC ) AS tmp
GROUP BY tmp.luku
Returns row '2 | toka | 1'

The aim is to get result even if there's no row holding the value 'toka' for the column 'arvo'

Is there a way to achieve the same result without a subquery?
SELECT * FROM `test2` GROUP BY luku ORDER BY arvo='toka' DESC
doesn't work as result set is first grouped by GROUP BY and thereby the row holding value 'toka' for column 'arvo' is omitted before sorting. (and there isn't a way to switch the order of the ORDER BY and GROUP BY?)

Thanks in advance,
Jesse

Options: ReplyQuote


Subject
Written By
Posted
group by - order of omitted rows
July 26, 2005 02:27AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.