Tuesday, October 26, 2010

Re: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

> Things.objects.filter(id__in=Things.objects.values('name').annotate(max_id= Max('id')).values_list('max_id',
> flat=True))

I didn't do values_list because I guessed that the inner query would
run and produce an array, then the outer query would run.

My way, with values() on both sides of the aggregate(), MIGHT insert
the inner SELECT statement into the outer one, like our SQL examples.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment