Using SELECT Statement with ORDER BY Clause - SQL Query

SQL ORDER BY clause is used to sort data in ascending and descending order. Some databases sort query results in ascending order by default.

Consider the following table 'Students'.

Stud_IDNamePhoneCityCountry
1Alex654124PerthAustralia
2Martin654125SydneyAustralia
3Shruti910001DelhiIndia
4Jaya910002MumbaiIndia
5Paul450525LondonEngland
6Andrew450526LondonEngland

I) Display column Name in ascending order from table Students.

The following query will sort name column in ascending order.

SELECT Name FROM Students
ORDER BY Name


Result:

Name
Alex
Andrew
Jaya
Martin
Paul
Shruti

II) Display names of the students from the table 'Students' in descending order.

SELECT * FROM Students
ORDER BY Name DESC


The following query will display the names of the students in descending order.


Stud_IDNamePhoneCityCountry
3Shruti910001DelhiIndia
5Paul450525LondonEngland
2Martin654125SydneyAustralia
4Jaya910002MumbaiIndia
6Andrew450526LondonEngland
1Alex654124PerthAustralia