id Bookname
----------------------
1 GlobleWorld
2 Tunner
3 Roster in city
4 GNom
5 Three mistake
6 other,Not specified
7 The Secret
8 inspiration
give result order by bookname but last row must be a "other,Not specified"
like this
-------------------------------------------------------------------------
id Bookname
----------------------
1 GlobleWorld
4 GNom
8 inspiration
3 Roster in city
7 The Secret
5 Three mistake
2 Tunner
6 other,Not specified
----------------------
1 GlobleWorld
2 Tunner
3 Roster in city
4 GNom
5 Three mistake
6 other,Not specified
7 The Secret
8 inspiration
give result order by bookname but last row must be a "other,Not specified"
like this
-------------------------------------------------------------------------
id Bookname
----------------------
1 GlobleWorld
4 GNom
8 inspiration
3 Roster in city
7 The Secret
5 Three mistake
2 Tunner
6 other,Not specified
SELECT *,ROW_NUMBER() over(order by Bookname)as rnk,
ReplyDeleteFROM Tablename
where ID not in(select id from Tablename where Bookname = 'other,Not specified')
union all
select * , '' from Tablename
where ID in(select id from Tablename where Bookname = 'other,Not specified')