SQL - Order By default sort order - Programmer and Software Interview Questions...
source link: https://www.programmerinterview.com/database-sql/sql-order-by-default-sort-order/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
In SQL, what is the default sort order of the Order By clause?
By default, the order by statement will sort in ascending order if no order (whether ascending or descending) is explicitly specified. This means that because the default sort order is ascending, the values will be sorted starting from the “smallest” value to the largest. This is true in all major RDBMS’s – including MySQL, Oracle, Microsoft SQL Server, Teradata, SAP, and others.
An example showing the Order By default sort order:
Take a look at the simple table below.
Customers
cust_id cust_name 79 Joe 32 Bill 87 Akash 14 Sam
Now, let’s write some SQL to retrieve the cust_name values sorted by their respective cust_id’s, but note that we do not specify whether to sort by descending or ascending order:
select cust_name FROM Customers ORDER BY cust_id
Because the order by will work in ascending order by default, the SQL above will return the following results:
cust_name Sam Bill Joe Akash
Now you have seen the default behavior of the Order By clause in SQL – it will sort in ascending order.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK