Can Group Functions Be Mixed with Non-group Selection Fields

Q

Can Group Functions Be Mixed with Non-group Selection Fields? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY

✍: FYIcenter.com

A

If a group function is used in the SELECT clause, all other selection fields must be group level fields. Non-group fields can not be mixed with group fields in the SELECT clause. The script below gives you an example of invalid SELECT statements with group and non-group selection fields:

mysql> SELECT COUNT(*), url FROM fyi_links;
ERROR 1140 (42000): Mixing of GROUP columns 
   (MIN(),MAX(),COUNT(),...) with no GROUP columns
   is illegal if there is no GROUP BY clause

In this example, COUNT(*) is a group field and "url" is a non-group field.

2007-05-11, 5373👍, 0💬