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.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.