← Fullstack with Vue.jsQuestion 43 of 62
When is annotate() guaranteed to generate a GROUP BY in Django ORM?
📘 Explanation
An aggregate function like Count, Sum, Avg, Max, or Min is what triggers a GROUP BY in annotate(), and whether values() is placed before or after annotate() determines the grouping columns versus just the output shape. The wrong answers either claim GROUP BY always happens regardless of aggregates, invent a subquery fallback, or claim grouping is always on the primary key, none of which match Django's actual behavior.
Related questions
- What's the difference between annotate() vs values().annotate() in Django ORM?
- What does Django's extra() method do, and when would you use it?
- When do you use selectrelated() vs prefetchrelated() in Django?
- Given a Book model with a ForeignKey to Author, how do you query the most expensive book per author in Django ORM?
- What does QuerySet.defer() do in Django ORM?
← PreviousNo login needed