INSERT in MySQL 5.1 and 5.6 and then SELECT returns in a different order -
im trying 2 inserts 2 databases on different servers. 1 running mysql 5.1 (on nas) , mysql 5.6 (on ubuntu).
i simple
insert table(pri1,pri2,value) values (1,1,1); insert table(pri1,pri2,value) values (1,2,1);
in order.
when a
select * table;
mysql 5.6 returns
pri1 pri2 value 1 1 1 1 2 1
which correct because order inserted.
when same thing (insert in same order , select) mysql 5.1 returns:
pri1 pri2 value 1 2 1 1 1 1
basically stores data in reverse , displays in order. why happen , how can prevent shows data correctly in mysql 5.6 ?
thank you
if need guaranteed specific order have use order by
-clause, i.e.
select * your_table order your_column desc
without order by
-clause, may appear if result in same order inserted them. not case. order may affected factors indexes or caching.
by default, rows in result set produced
select
statement returned server client in no particular order. when query issued, server free return rows in convenient order. order can affected factors such order in rows stored in table, or indexes used preocess query. if neccessary output rows returned in specific order, icludeorder by
clause indicates how sort results.
source: "mysql developers (4.2.5 using order in select statements) - oracle 2011"
Comments
Post a Comment