SQL ORDER BY Keyword

0
285

sqltuts

It defines how the records are to be sorted. By default, it is to order in ascending order(ASC). If we want to sort in descending order, we can use DESC after the column name.

 

Syntax:

 
[sql] SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC/DESC, column_name ASC/DESC;
[/sql]  

For example, consider the following table Employee:

 

Employee_id First_name Last_name sex
123 Mack Johnson male
124 Jack Obama male
125 King Khan male

 

 
[sql] SELECT * FROM Employee
ORDER BY Employee_id DESC;
[/sql]  

 

This would give the following output:

 

Employee_id First_name Last_name sex
125 King Khan male
124 Jack Obama male
123 Mack Johnson male

 

 

 

 

 

 

 

Previous articleSQL UNIQUE Constraint
Next articleHow to Create Simple Shopping Cart in PHP 2019
Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.