Skip to content
Advertisement

First rows for selected cid then show the others rows

I have orders table like this:

OID CID ODATE 
1    1  01/01/21
2    2  01/02/21 
3    2  20/01/21 
4.   3. 20/01/21 
5.   4. 20/01/21 

I want to see all the orders of cid 2 first then all the others thanks …

Advertisement

Answer

You may order using a CASE expression:

SELECT *
FROM yourTable
ORDER BY CASE CID WHEN 2 THEN 1 ELSE 2 END;

You may also add more sorting levels after the above CASE expression.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement