When filtering a queryset, I’m wondering if the following are equivalent.
User.objects.filter(username='josh').filter(email__startswith='josh')
User.objects.filter(username='josh', email__startswith='josh')
I can’t imagine how the generated SQL could be any different between the two. The documentation doesn’t seem to mention any differences either.
You can execute those queries in the shell and print out the generated SQL like:
I tested a similiar queries like you got here and there was no difference in the generated SQL code.Both statements end up using them same WHERE Statement.
Furhtermore it shouldnt make any difference in this case whether you chain the filters or apply them in one step.
But there are scenarios in which the order of filtering matters.
Have a look here and here.