Let's say I have a SELECT statement as follows:
SELECT ..., field1
FROM ...
GROUP BY field1
Now let's say I want to return a second field, field2
. As it happens, field2 is functionally dependent on field1 (for example, field1 and field2 could be from the same table and field1 is the primary key of that table). I now have two equivalent ways to add field2 to the query:
Option 1:
SELECT ..., field1, field2
FROM ...
GROUP BY field1, field2
Option 2:
SELECT ..., field1, MIN(field2) /* or some other, arbitrary aggregate function */
FROM ...
GROUP BY field1
Again, since field2 functionally depends on field1, both queries should return the same result set.
Are there any good reasons to prefer one option over the other?