Thanks Alex, I tried it, and it results in 3 queries. On Jan 20, 12:44 pm, Alex_Gaynor <alex.gay...@gmail.com> wrote: > On Jan 20, 12:46 am, django_user <amalt...@gmail.com> wrote: > > > I am not sure if the following statements in Django/Mysql will result > > in one or three database queries. > > > candidates = Candidate.objects.filter(department = dept).order_by('- > > salary')[:30] # Gets all the top salary candidates > > head_candidates = candidates[:20] # Gets top 20 > > tail_candidates = candidates[20:30] # Gets remaining 10 > > > Is there a better way to do it, or is this fine :) > > I believe that results in 1 query, however if you want to be certain > you can always pull up the dev console, and do: > > >>> from django.db import connection, reset_queries > >>> reset_queries() > >>> # YOUR CODE HERE > >>> connection.queries > > To see what SQL it runs. Make sure you have DEBUG=True when you do > this. > > Alex
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.