Press "Enter" to skip to content

When GROUP BY Order Matters

Brent Ozar runs some tests:

Sometimes when you do GROUP BY, the order of the columns does matter. For example, these two SELECT queries produce different results:

Their actual execution plans are wildly different:

Click through to learn when the ordering in a GROUP BY clause matters and when it doesn’t.