Hello to all,

I searched this list's archive, but I couldn't find a solution to a problem I am currently facing.
Any help would be appreciated.


I have the next table configuration: session (an session id), weight (a counter), and other fields.
When I add a new record and the session id I am tring to add doesn't exist in the table, the
weight field is set to 1, other wise the weight field is set to the maximum weight field + 1 found
for the same session id.


The problem: I want a query to get all the distinct session ids, but for each session id I want it
to return the last record in the order of the weight field.


I tried the following query:

select *, count(*) as cnt from table group by session having weight=cnt

But the problem is HAVING is applied after the grouping. I want my condition (weight=cnt) to
be processed before the grouping. I can't add it in the Where clause because of cnt.


How can I do this ?


Valentin Agachi


_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus



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



Reply via email to