Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table like below

FirstName | LastName | YearOfBirth
----------------------------------------
Thomas | Alva Edison | 1847
Benjamin | Franklin | 1706
Thomas | More | 1478
Thomas | Jefferson | 1826

I want to sort by both columns like 'Lastname ASC' and 'YearOfBirth ASC'

Is it possible??Can anyone help me.

What I have tried:

I tried ,but only for one column is working.For both columns it is not working.
Posted
Updated 10-Jun-16 3:00am
Comments
Nigam,Ashish 29-Apr-16 6:47am    
Please mention your current sql query.

try ..
SQL
SELECT * FROM table ORDER BY Lastname DESC, YearOfBirth ASC
 
Share this answer
 
Comments
Maciej Los 10-Jun-16 9:07am    
5!
Quote:
Is it possible??Can anyone help me.
It is possible to order by a column and then by another one (see, for instance MSDN[^]). In your scenario it would be
SQL
... ORDER BY Lastname ASC, YearOfBirth ASC;

Please note, in your sample data the ordering by 'YearOfBirth' would be irrelevant.
 
Share this answer
 
Comments
Maciej Los 10-Jun-16 9:07am    
5ed!

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