On Tue, 12 Feb 2019 13:31:59 +0100
Clemens Ladisch <[email protected]> wrote:

> SQLite allows to SELECT columns that are not mentioned in the GROUP
> BY clause, but they get their values from a random row in the group.

Thank you for pointing this out! I was aware of the row being
random when selected this way, but I didn't realize that it wasn't
standard SQL. One more reason to avoid SELECTs like this, then.

> There is another SQLite extension which allows to select a row in the
> group by using MAX() or MIN():
> 
>   select *, min(abs(source_id - 3)) from test where id in (1,2) group
> by id;

I'm afraid to use this because the queries I'm considering now may be
reused later in a different SQL engine, and a shortcut like this might
be easy to look over. Maybe I should just select min(abs(source_id-?))
because it is so much simpler, leave a comment and worry about it
and the more general cases later (if ever).

-- 
Best regards,
Ivan
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to