Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Allow for omitting "functionally dependent" columns in GROUP BY

Lukas EderJul 11 2016

The SQL standard specifies that "functionally dependent" columns do not need to be listed in a GROUP BY clause, yet they are still usable in SELECT, HAVING, and ORDER BY. For example:

SELECT d.name, COUNT(*)

FROM employees e

JOIN departments d USING (department_id)

GROUP BY department_id

In the above example, there is a primary key on d.department_id, and pretty "obviously", there can be only one d.name per d.department_id, so the current requirement to list all columns from the SELECT clause also in the GROUP BY clause seems too restrictive.

PostgreSQL (for example) already implements the SQL standard. When working with PostgreSQL, using GROUP BY is much more enjoyable than in current versions of Oracle, so this would be a great addition.

(Note: This is NOT the same as what MySQL is doing. MySQL doesn't care about functional dependency and just selects arbitrary values per group, in case there is an ambiguity. With a formal functional dependency, there can never be ambiguity, and listing the extra column in GROUP BY is unnecessary)

Comments
Post Details
Added on Jul 11 2016
13 comments
2,568 views