How about

select ID, X, Y, Z from USERS order by ID desc limit 1


Tim

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 10, 2006 5:47 PM
To: mysql@lists.mysql.com
Subject: MAX() and GROUP BY question

Hello everybody
Can you explain me please how to get the entire row where ID is maximum per
given status_id
Mysql 4.0.xx 

for example:

id status_id    name        date
6     3           name0      date0
5     1           name1      date1
7     4           name3      date3
10   3           name2      date2

If I execute 

SELECT MAX(id), status, name, date FROM table_name WHERE status=3 GROUP BY
staus_id
or
SELECT MAX(id), status, name, date GROUP BY staus_id

only id and status_id will be returned correctly, while name and date can
well be from another row
for example: 10 3 name0 date0


Thanks a lot for any suggestions
Yannis



-- 
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