i have a database with: city / age for example: Chicago 24 York 33 Chicago 54 London 12 York 21 London 1
How can i oreder thing like this? Chicago 24 Chicago 54 Yor开发者_StackOverflowk 33 York 21 London 1 London 12
Basically order them by the name of the town. I use this for a php display records script.
mysql_query("SELECT * FROM towns WHERE .........");
To change the order of the results you use ORDER BY, not WHERE.
SELECT city, age
FROM towns
ORDER BY city
If you want the cities in the order in your example then use FIELD:
SELECT city, age
FROM towns
ORDER BY FIELD(city, 'Chicago', 'York', 'London')
Try
SELECT city, age FROM towns ORDER BY city DESC, age;
That will order by city DESC first and then age [ASC] second... which is what I believe you require.
加载中,请稍侯......
精彩评论