简体   繁体   中英

Mysql primary keys not coming in order

Select * from user_table;

is giving the results in a order but when I am fetching only one column like

Select user_id from user_table; then the user_ids are not coming in order.Please tell me the reasons or any help to solve this problem.Please observe the following links for result pages.

http://i.stack.imgur.com/rJ429.jpg http://i.stack.imgur.com/Sd1yS.jpg

SELECT user_id from user_table order by user_id ASC;

Part of the "SQL contract" is that there is no default order to rows that you SELECT . The database engine is free to present them in any order that is convenient for it to do. This order is likely to change based on the columns you return (to take advantage of instances in which the entire query can be satisfied by reading from indexes only) and can also change based on the WHERE clause used to retrieve the records. It may also change from day to day or version to version for no apparent reason.

In order to be confident in the order of the rows returned, you must supply an ORDER BY clause with sufficient specificity to guarantee exactly the order you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM