Back to Blog

Beginning SQL

SQL Order By

Sort query results with SQL ORDER BY clause. Master ascending/descending sorts, multiple column ordering, and NULL handling in SQL Server databases.

2 min read

Last updated on

The SQL Order By allows you to sort your results when you run a SQL Query.

Let-s look at an example:

select * from employee order by employee_name;


This will sort by the **employee_name** column.

Here are the results:

![image](../../assets/blog/2012/06/image_thumb10.png)

If you want to change the sort from **Ascending** (which is the default) to **Descending**, you would write your query as follows.

select * from employee order by employee_name desc;

With the following results:

![image](../../assets/blog/2012/06/image_thumb11.png)

You can also sort by more than one column.

select * from employee order by job asc,employee_name desc;

Notice how **job** and **employee_name** columns are both sorted.

![image](../../assets/blog/2012/06/image_thumb12.png)

And the last trick is that you can use the column number. In this case I will sort by the 3rd column (job) then the 2nd column (employee_name).

select * from employee order by 3 asc,2 asc;

Notice that I changed the employee_name column to sort ascending.

image

And that-s it for the **SQL Order By **clause.

Leave any comments or questions below.

About Joey Blue

Joey Blue teaches practical data skills that companies actually use. With 25+ years of experience solving real data problems for Fortune 500 companies, he's helped 152,000+ students learn SQL, Power BI, reporting, and modern analytics—cutting straight to what works.