I have a table like:
-------------------
id class name sub
------------------------
1 mca aditya network
2 mca abhishek daa
3 mca akhilesh algorithm
4 btech ram cs
5 btech shyam ds
6 btech anand client/server
7 mba furqan os
8 mba arvind marketing
9 mba aayush hr
I want a result set like the following:
----------------
class name sub
------------------------
mca aditya network
abhishek daa
akhilesh algorithm
btech ram cs
shyam ds
anand client/server
mba furqan os
arvind marketing
aayush hr
I think you may be better off handling this in your UI / Display tier, but if you need the query to do it in SQL 2008, you can use a CTE with ROW_NUMBER()
I’m not sure what sort / order you’re looking for. Your example appears to still be ordered by Id. If you want this, you can add the Id column into the
ordered CTEand then addORDER BY o.Id ASCat the end of the query.