Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL 5: Does it matter what order my GROUP BY fields are in?

Peeps,

I have a few aggregate/calculated fields in my MySQL query. My GROUP BY clause is dynamically generated, depending on what options a user selects in a web form. Curious if the order of fields listed in the GROUP BY clause can have any impact on the calculations (things like SUMs, AVERAGEs, etc)

Thanks!

like image 902
idiocrash Avatar asked Oct 18 '25 19:10

idiocrash


1 Answers

It WILL matter if you are using WITH ROLLUP, otherwise, it should not.

like image 79
gahooa Avatar answered Oct 21 '25 08:10

gahooa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!