samedi 23 avril 2016

Why this patrially non-aggregated group-by works?

Any idea why the following two queries produce the same results? According to all references I've seen, the first shouldn't even work, but it does. Obviously, if its not a glitch, I prefer the first as it's a simpler and probably faster query.

SELECT *,MIN(ts) FROM tbl GROUP BY id;

SELECT *,ts FROM tbl a WHERE rowid IN 
     (SELECT rowid FROM tbl b WHERE a.id = b.id ORDER BY ts LIMIT 1);

Aucun commentaire:

Enregistrer un commentaire