Using group by without an aggregate function

It is interesting to find that in MySQL, you can write the following:
select * from orders o join order_tender ot on ot.order_id = o.id group by o.id
This doesn’t really make sense, since the purpose of “group by” is to group records when you are using an aggregate function, such as sum. e.g.
select o.id, sum(ot.value) from orders o join order_tender ot on 
ot.order_id = o.id group by o.id
If you want to read some ideas as to why the MySQL folks permit this, see: http://stackoverflow.com/questions/1225144/why-does-mysql-allow-group-by-queries-without-aggregate-functions
This entry was posted in MySQL and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags are not allowed.

517,978 Spambots Blocked by Simple Comments