C# .NET - How to define custom sort order based on description field sql

Asked By abc V on 27-May-13 02:33 PM
I have a department field where i need to sort the data based in description field

I need to get the Science department, Social department, Games department and then get the rest of the description fiedls ascending order, I am not sure how to do that in sql I just know asc or desc order sort in the sql table for any fields/ ,ultiple fields. Please help how to achieve this.
Bill B replied to abc V on 14-Jun-13 03:33 AM
select department, description from yourSchoolTable
order by department, description

list the fields in the precedence order you want them sorted
that one sorts by department first, and if you have two departments of same value, then description will sort the return order

It defaults to ascending order, so you would only put in desc when you want it reversed.


select department, description from yourSchoolTable
order by department DESC, description

would reverse the department sorting

select department, description from yourSchoolTable
order by description, department

that would sort by the description first, and if they were the same, then it would sort by department

select department, description from yourSchoolTable
order by professorName DESC, description DESC, department DESC

and that would sort by your class teacher name first

RTFM

go look that one up. It's funny.