by rows of a MySQL SELECT query are displayed in an arbitrary order or unpredictable. Since the return is more inside and hash algorithms that search for what you do with your data, the order of the rows is generally not useful to a developer. To return the rows of an order, you can use the ORDER BY clause of the SELECT to sort the base .
Form SELECT to return the rows in which you are interested. At this point, the order in which rows are returned is not of importance. This example queries a customer database for a list of customers with negative balances. Example: SELECT * FROM customers WHERE balance <0.0 ;
Add an ORDER BY clause. ORDER BY, MySQL will tell the server to sort the rows by a column. For example, if you want to see all outstanding accounts to balance, you can add "ORDER BY balance" at the end of the consultation. Example: SELECT * FROM customers WHERE balance <0.0 ORDER BY balance ;
Define in which direction to sort, as the order of the rows returned may not yet be meaningful. You can return the rows in ascending or descending order .
use ASC or DESC. Using the ASC order for you to see the smallest number first. DESC using the data type for you to see the largest number first. In this consultation, which seeks customers with the highest negative balance in the first place. ORDER BY return the array with the largest negative number (the smallest) at the top. Example: SELECT * FROM customers WHERE balance <0.0 ORDER BY ASC balance ;
Sort by multiple columns, as sometimes you'll come across large groups of rows that were ordered in the same issue. For example, if there are 100 customers in its database with a balance of 0, users appear in arbitrary order. It is better to have at least two criteria to classify this type of situation .
Using multiple criteria classification separated by commas. Here, customers are shown in alphabetical order by name after they are sorted by the balance. Example: SELECT * FROM customers WHERE balance <0.0 balance ORDER BY name ASC