?
Solved

Turning off the automatic Ascending order in MySQL for results

Posted on 2016-07-27
4
Medium Priority
?
38 Views
Last Modified: 2016-08-01
MySQL is automatically ordering my result set in alphabetical or ascending order by the first column noted in the Select clause. How do I turn this off so that the results will show in the order in which the records appear in the database?
0
Comment
Question by:chonabraham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 41

Expert Comment

by:Sharath
ID: 41731750
There is no guarantee on the order of records if you do not specify ORDER BY explicitly. so include ORDER BY and mention whatever the column you want.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 41731777
SQL databases including MySQL usually use a tree structure internally to store records.  It is not linear like a spreadsheet.  The tree structure makes a lot of things easier in a database.  

When a record in the tree is deleted, the next record that is inserted takes it's place.  Because of that and the tree structure itself, there isn't any 'default' sorting in an SQL table.  Like Sharath said above, use ORDER BY if you want a particular order to the results.
0
 

Author Comment

by:chonabraham
ID: 41732171
But in Access, the results are displayed the way they are entered into the table so then you must use order by to get results in asc or desc by a particular column or collection of columns. I converted an Access table into script then ran it in MySQL to create and insert data into a table in the same order as it appears in the original Access table but when I select from the MySQL table the result is automatically sorted in alphabetical order by the first attribute in the select clause. Therefore, I thought there must be some kind of default setting that automically provides results in this order.
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 41732182
No.  There is no pre-defined sort order in SQL tables.  The table may appear to be sorted but any number of things can change that if you are not using an ORDER BY clause.  The only ways to get the INSERT order are to use an 'autoincrement' column or to have a DATETIME column that gets populated as you insert rows (usually using a NOW() command).  Those just give ORDER BY something to work with.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question