Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

SELECT DISTINCT ON expressions must match initial ORDER BY expressions django

from django.db.models import Subquery

Model.objects.filter(
    pk__in=Subquery(
       Model.objects.all().distinct('foo').values('pk')
    )
).order_by('bar')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #SELECT #DISTINCT #ON #expressions #match #initial #ORDER #BY #expressions #django
ADD COMMENT
Topic
Name
9+3 =