r/SQL • u/Harshita_Netla • Sep 21 '26
MySQL Practicing window functions and keep mixing up PARTITION BY vs GROUP BY — how are they actually different?
They both seem like they divide data into groups, so I’m having trouble understanding when I should use one instead of the other.
47
Upvotes
View all comments
Show parent comment
5
u/Strict-Ambition4334 Sep 21 '26
One small correction: PARTITION BY needs to come before ORDER BY inside OVER. So
ROW_NUMBER() OVER (PARTITION BY Category ORDER BY Price DESC), not the other way around. The underlying point still holds.