MySQL case when according to the conditions of the results

Data:
The A table
id info
The 1 delay
2 heavy brush
3 test
4 to test the success of


To go to:
The 4 data, when there is ID to 1,2 when I take 2 of the data, i.e. data access priority is: 2431, the above 4 data is not always exist at the same time, there may be only 1, 4, it would take 4 data,


Thank you

Started by Ives at November 17, 2016 - 3:17 PM

Simple, you add a column position reed.


id info pos
The 1 delay 2
2 heavy brush 4
3 to test 3
4 to test the success of 1


select * from tb order by pos

Posted by Harrison at November 29, 2016 - 3:58 PM

This method is good!

Posted by Webb at December 14, 2016 - 4:47 PM

select *
The from A table
order by find_in_set(id,'2,4,3,1') 
limit 1

Posted by Cassandra at December 21, 2016 - 5:22 PM

First floor: add a column support, sort priority, after the order by query feel more flexible, easy to expand!

Posted by Ariel at December 26, 2016 - 5:54 PM

Thank you, in the background of Java processing, also added a priority field, database processing is not good to make (and other tables)

Posted by Ives at January 07, 2017 - 6:40 PM