Search code examples
sqlrdbms

How to movie particular user in top by default


I have a table with this structure,

Topic

  1. UserID
  2. TopicID

Roles

  1. Admin
  2. Users

UserInROles userID RoleID

enter image description here

My Requirement,

By default (admin role) topicid should show always in the top .

Note : There will be only one admin.

Admin Userid : 10

wherever i am executing the query,i need to get admin topic should be On the top

This was i am trying to get result

enter image description here

Sagar For your answer,(but check my result how i am expecting) enter image description here


Solution

  • --This will help you

    select * 
    from tblTable 
    order by (case id when 10 then 0 else 1 end), dbo.id desc