No, this won't work
I actually have a table of support ticket records

record_id
ticket_id
date
name
status
department_id
and other columns

I must select an ordered list of ticket_id where each row is the most recent 
record of gived ticket: max(record_id) for given ticket_id

I currently solved this using two queries: 
First will select a list of max record_id's: SELECT MAX(record_id) GROUP BY 
ticket_id
Then using API I create a comma separated list of record_id's.
Then I select the latest records of each ticket: SELECT * WHERE record_id IN 
(........)

I just wonder if there is more optimised solution

Thanks a lot

----- Original Message ----
From: Tim Lucia <[EMAIL PROTECTED]>
To: mysql@lists.mysql.com
Sent: Saturday, November 11, 2006 3:56:49 PM
Subject: RE: MAX() and GROUP BY question


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]



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

Reply via email to