3 ms·
Hi ris, Can you provide example(s) of the broken query with non-GROUP BY columns in an aggregation? (Or a reference link if this is well known - I've searched
by ak39 8y ago
Hi ris,
Can you provide example(s) of the broken query with non-GROUP BY columns in an aggregation? (Or a reference link if this is well known - I've searched briefly but can't find anything.)
- lmz 8y agoNot the parent poster but it's queries like these: Select user.id, user.name, sum(tx.amount) from user inner join txn on (user.id = txn.uid) group by user.id User.name is not in the group by list so it is picked arbitrarily from the rows in the group. It's harmless here but not in all cases.
- Groxx 8y agoTBH I like the ability to do this. Sometimes you truly don't care which value you get, you just want one. Sometimes you have application-level constraints which mean the one it picks is guaranteed to be correct, but you can avoid the cost of enforcing that (at insertion time and at lookup time). It's a handy tool when it's appropriate. But hell yes, tools should warn you about this loudly, as it's not generally correct.