Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is it possible to use order by column name for more than 1 column in a sql database? i mean can we use order by column combining more than one column in a sql. like order by column A and column B.
Posted

Very much possible. Following is syntax for SELECT statement where multiple columns are used in ORDER BY clause.

SQL
SELECT column_name1, column_name2
FROM table_name
ORDER BY column_name1 ASC|DESC, column_name2 ASC|DESC;


ASC|DESC meaning you can use either of them.
 
Share this answer
 
v2
Comments
Adarsh chauhan 12-Aug-13 7:15am    
+5
Maciej Los 12-Aug-13 7:17am    
Agree.
+5!
ARUN K P 12-Aug-13 7:17am    
ok thank you
+5
Maciej Los 12-Aug-13 7:18am    
Arun, please, mark all useful answers as a solution (green button) to remove your question from unanswered list.
ARUN K P 12-Aug-13 7:22am    
u mean i have to click accept solution button right?
Yes, it is possible. Please, see here: ORDER BY Clause (T-SQL)[^]
 
Share this answer
 
Comments
ARUN K P 12-Aug-13 7:17am    
+5
Maciej Los 12-Aug-13 7:19am    
Thank you.
Have you seen my comment to the solution 1?
Adarsh chauhan 12-Aug-13 7:20am    
+5 from me also.. :)
Maciej Los 12-Aug-13 7:26am    
Thank you ;)
ARUN K P 12-Aug-13 7:22am    
yeah maciej los thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900