On 16/05/07, Glauco <[EMAIL PROTECTED]> wrote:
>
> are you searhing for ?
>
> select max( changeTime ) from OrderDiscount  group by orderID ;   ?
>
> i don't understand well what you are searching for
>

Thanks to all of you!
I actually needed the last message itself - more than just its date.
Thanks to your help, I came up with this:

# Create the 'maxdates' select, which gives for each user (which
posted a message) the date of his most recent post
maxdates = select([messages.c.user_id.label('uid'),
func.max(messages.c.date).label('maxdate')],
group_by=messages.c.user_id).alias('maxdates')

# Select only the last message for each user
lastmessages = select([messages],
and_(messages.c.user_id==maxdates.c.uid,
messages.c.date==maxdates.c.maxdate), group_by=messages.c.user_id)

I added the group_by to the last select so that if there are two
messages from the same date only one will be selected.
I added the alias maxdates to the first select because otherwise mysql
complained that 'Every derived table must have its own alias'. I think
that it's a bug in sqlalchemy - adding the alias added no information
about the query, so sqlalchemy should have created an alias by itself.
Am I correct?

Thanks again,
Noam

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to