Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have data in table -> bp like below

1 Vendor
2 Customer
3 Transporter
I want select * from bp order by row value 2,1,3, like this the result should be:

2 Customer
1 Vendor
3 Transporter
Posted

1 solution

Well, for simple operations:
SQL
SELECT * FROM bp
ORDER BY CASE WHEN value = 2 THEN 1
              WHEN value = 1 THEN 2
              ELSE value 
         END
But for bigger tables you are going to have to either decide on some rules instead of absolute values or add an "Ordering" column to your table. (I'd go for the extra column, myself)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900