mysql - Will DISTINCT always return a same order of values for a same SQL? -
i have sql statement pattern
select id table [conditions] order [orders] limit 10000 offset 0 and return value below:
id ----- 1 0 0 0 0 1 1 1 2 2 ... then want distinct value order of first appearance, since there's order in sql, , distinct or group both happened before order in sql, tried below sql.
select distinct id (select id table [conditions] order [orders] limit 10000 offset 0) tmp; and result want:
id ---- 1 0 2 ... my question is: can ensure in same pattern sql, distinct return distinct id order first appearance?
thanks.
---------------notes------------------
below can ignored. noticed many peoples recommended try group by, tried below sql well:
select id (select id table [conditions] order [orders] limit 10000 offset 0) tmp group id; but returning reordered alpha-beta order (it's not integer order because column char column real id string), not want.
id ---- 0 1 10 100 ....
if want results in particular order, need specify in order by outermost select. suggests this:
select id tabl [conditions] order [orders] limit 10000 offset 0 then, if want order first appearance, need column specifies first appearance. let's call createdat (perhaps orders?). if so:
select id table conditions group id order min(createdat) limit 10000; note: sql tables represent unordered sets, need column specify ordering of interest.
Comments
Post a Comment