joon1
1
select id, name from countryorder by name
I have the code above and the result of it is follow.
4 Canada
2 China
1 France
5 Germany
3 Japan
6 Korea
I like to designate the order directly by my own designating order.
I mean I like to make the order Germany first, and Korea 2nd, and France 3rd and the rest of it is by name
My target result is bellow.
5 Germany
6 Korea
1 France
4 Canada
2 China
3 Japan
The code below does not work correctly, but I hope it shows what I want.
select id, name from country order by name.Germany, name.Korea, name.France, name
Add a column to the table to store the order in which you want the results to be displayed.
Then do an ORDER BY on that coliumn
joon1
3
if my own designating order is dynamic, then maybe I cannot add a column to the table.
Is there any way for order designating by value?
r937
4
... order by name.Germany, name.Korea, name.France, name
no… that’s not even valid syntax
try this –
ORDER
BY FIELD( name
, 'Germany'
, 'Korea'
, 'France'
, 'Canada'
, 'China'
, 'Japan'
)
system
Closed
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.