you would need to create a temporary table. So lets say you want to check
'id' column for highest value, you would do the following:

CREATE TABLE tmp SELECT MAX(id) AS max_id FROM tbl;
SELECT * FROM tbl WHERE tmp.max_id = tbl.id;

Another approach would be to use an SQL variable, again if you want to check
'id' column for highest value, do the following:

SELECT @max_id := MAX(id) FROM tbl;
SELECT * FROM tbl WHERE tbl.id = @max_id;


-----Original Message-----
From: Yves Goergen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 20, 2003 2:29 PM
To: List: MySQL
Subject: How to 'customize' GROUP BY?

Hi again...
yet another question to this list that maybe someone can easily answer me...

When I do a GROUP BY on a column of my query, I'll get one random row from
the entire group. But how can I tell MySQL to, i.e., give me the row with
the highest value of another column or so? I mean something like

    SELECT id, grp FROM tbl GROUP BY grp ORDER BY id

but with the ORDER BY relating to the GROUP... I don't know how to express
this in SQL since it doesn't seem to be possible?

-- 
Yves Goergen
[EMAIL PROTECTED]
Please don't CC me (causes double mails)


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to