skip to Main Content

I wanna select data from table with ordering where first I’ll get values with specific value.

I tried this but it didn’t work:

SELECT name FROM test ORDER BY id ='d189463e-52dc-40e5-adf7-eddce74cf05e';

2

Answers


  1. use a case expression This allows you to define whatever "ordering" you want for the IDs

    SELECT name 
    FROM test 
    ORDER BY CASE WHEN ID = 'd189463e-52dc-40e5-adf7-eddce74cf05e' THEN 1 
                  WHEN ID = ... ELSE ... END;
    
    Login or Signup to reply.
  2. I would write

    ORDER BY id <> 'd189463e-52dc-40e5-adf7-eddce74cf05e'
    

    or

    ORDER BY id = 'd189463e-52dc-40e5-adf7-eddce74cf05e' DESC
    

    because FALSE < TRUE.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search