By default, the order by statement will sort inascending 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.
Take a look at the simple table below.
Customers | ||||||||||
|
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_nameFROM CustomersORDER BY cust_id
Because the order by will work inascending order by default, the SQL above will return the following results:
cust_nameSam BillJoeAkash
Now you have seen the default behavior of the Order By clause in SQL – it will sort in ascending order.
Would you like to thankProgrammerInterview.com for being a helpful free resource?Then why not tell a friend about us, orsimply add a link to this page from your webpage using the HTML below.
Link to this page:
Please bookmark with social media, your votes are noticed and appreciated: