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

Viewed 36

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?

1 Answers

You can try using case:

   select ...
 order by case
            when idcard = 3 then 1
            else 0
          end,
          idcard
Related