Some databases sort the query results in an ascending order by default.

CustomerName: The following SQL statement selects all customers from the "Customers" table, returned in descending order. The following SQL statement selects all the columns from the "Customers" SQL | ORDER BY Last Updated: 09-01-2019. SQL HOME SQL Intro SQL Syntax SQL Select SQL Select Distinct SQL Where SQL And, Or, Not SQL Order By SQL Insert Into SQL Null Values SQL Update SQL Delete SQL Select Top SQL Min and Max SQL Count, Avg, Sum SQL Like SQL Wildcards SQL In SQL Between SQL Aliases SQL Joins SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL Self Join SQL Union SQL Group By SQL Having SQL Exists SQL … The ORDER BY command sorts the result set in

Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. by Country, but if some rows have the same Country, it orders them by If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: W3Schools is optimized for learning and training. The DESC command is used to sort the data returned in ascending order. Below is a selection from the "Customers" table in the Northwind sample database: The following SQL statement selects all customers from the "Customers" table, The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns.

Consider the CUSTOMERS table having the following records −, The following code block has an example, which would sort the result in an ascending order by the NAME and the SALARY −, This would produce the following result −. The ORDER BY statement in sql is used to sort the fetched data in either ascending or descending according to one or more columns.

To sort the records in descending order, use the DESC keyword. sorted by the "Country" and the "CustomerName" column. The ORDER BY clause first sorts the retrieved data by the first column, then the next one, and so forth. You can use more than one column in the ORDER BY clause. sorted DESCENDING by the "Country" column: The following SQL statement selects all customers from the "Customers" table,

The ORDER BY command is used to sort the result set in ascending or descending order. This means that it orders The following code block has an example, which would sort the result in the descending order by NAME. The ORDER BY keyword is used to sort the result-set in ascending or SQL ORDER BY.

w3schools .com LOG IN sorted ascending by the "Country" and descending by the "CustomerName" column: Select all records from the Customers table, sort the result alphabetically by the column City. DESC keyword. The basic syntax of the ORDER BY clause is as follows −. table, sorted descending by the "CustomerName" column: If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: W3Schools is optimized for learning and training. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content.

ascending order by default. Examples might be simplified to improve reading and learning. A sort column can be specified as a name or column alias, or a nonnegative integer representing the position of the column in the select list. To sort the records in descending order, use the The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. While using W3Schools, you agree to have read and accepted our. descending order. Syntax. The following SQL statement selects all the columns from the "Customers" SQL ORDER BY explained. Examples might be simplified to improve reading and learning. Make sure whatever column you are using to sort that column should be in the column-list. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our. order_by_expression Specifies a column or expression on which to sort the query result set. Arguments. table, sorted by the "CustomerName" column: The ASC command is used to sort the data sorted by the "Country" column: The following SQL statement selects all customers from the "Customers" table, Some databases sort the query results in an ascending order by default. Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL) SQL | Procedures in PL/SQL; The ORDER BY keyword sorts the records in ascending order by default.