In sqlite, how are return values chosen for columns that are not used for aggregation or grouping?
The database will return the value from some arbitrary row in the group.
(In the current implementation, it's the value from that last row in the group that was processed, but due to indexes or other optimizations, the processing order might not be predictable.)

Since SQLite 3.7.11, using MIN() or MAX() guarantees that values from a row with the minimum/maximum value are returned.