Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP0universalStack: sql
sqlcorrectnessaggregationdatabase
Group by a unique, non-nullable key, not by a display field that can be null
GROUP BY should use a guaranteed-unique, non-nullable identifier (e.g. a primary key) rather than a label like a nickname that may be null or duplicated, to avoid collapsing distinct rows.
PR: hegnar-investor-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codesql
| 1 | SELECT COUNT(p.id), u.nick FROM users u ... GROUP BY u.nick |
Explanation (EN)
Objašnjenje (HR)
Good example
New codesql
| 1 | SELECT COUNT(p.id), u.id, u.nick FROM users u ... GROUP BY u.id |
Explanation (EN)
Objašnjenje (HR)