In sql, ORDER BY is used to sort the result set. 

Sorting by default is in ascending order. It means if nothing is mentioned then result set will be sorted in ascending order.

Alternatively, you can also instruct to sort in ascending order by keyword ASC on ORDER BY.


To sort in descending order use keyword DESC. We will learn more aboout it in next chapter.


Syntax for ORDER BY ASC

SELECT [*|columns]
FROM table_name
ORDER BY column1, column2,..., columnN ASC;



We will use tih_Courses table for demonstration purpose


Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
005 Blogging Tutorial Puja  Online
006 JSP Alok Pandey Online and Offline
007 Servlet Mukesh Tiwari Online and Offline

Query-1: Write a sql query to sort the data by Professor in ascending order.

SELECT FROM tih_Courses
ORDER BY Professor ASC;

We can also sort the data based on ultiple columns as well. We will study in next chapters.

Please Share this page
Views : 126
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!