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 …

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x