3 ms·
SQLite also has some weird (non-standard?) behavior when aggregating. If you forget to include a GROUP BY, SQLite will just pick a random value from the non-agg
by tqi 4y ago
SQLite also has some weird (non-standard?) behavior when aggregating. If you forget to include a GROUP BY, SQLite will just pick a random value from the non-aggregate columns. For example:
SELECT col1, COUNT(1) FROM table1;
happily returns a single row of data.
I struggle to understand why that is preferable to throwing an error?
- wruza 4y agohttps://www.sqlite.org/lang_select.html https://www.sqlite.org/lang_select.html Section 2.5, starting with: Special processing occurs when the aggregate function is either min() or max()
- Groxx 4y agoMySQL also does this. Personally I find it quite useful - I can avoid indexing costs or table scanning on things where either A: I know from an application level that any value is the same as all others for my query, or B: when any value is equally acceptable (e.g. to show an example result).