[Fixed]-How can I select and order items based on a subquery?

1👍

✅

Try this

Author.objects.all().annotate(s=Min('book__pubdate')).order_by('s')

When if some author dont have books

Author.objects.exclude(book__pubdate__isnull=True).annotate(s=Min('book__pubdate')).order_by('s')

Leave a comment