Tutorials

SQL ORDER BY


SQL ORDER BY DESC


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

 

To sort in descending order use keyword DESC.

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 read about sorting in ascending order click here. 

Syntax for ORDER BY ASC

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

Example

We will use tih_Courses table for demonstration purpose

tih_Courses
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 descending order.

SELECT FROM tih_Courses
ORDER BY Professor DESC;

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



Please Share this page
Views : 34
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!