Skip to content
Advertisement

How to order values with order by x asc but if x has a specific number like 3 to make it show last sql

I have this query

  select name, 
         surname, 
         age 
    from user 
order by idcard asc  

but I want that if idcard has values 3 those values to be shown together in the end of the list while the rest 1, 2, 4, 5, 6, to order by asc

is it possible to do?

Advertisement

Answer

You can try using case:

   select ...
 order by case
            when idcard = 3 then 1
            else 0
          end,
          idcard
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement