tags:

views:

23

answers:

2

Hello, 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 York 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 .........");
+1  A: 

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')
Mark Byers
Hmm is the syntax ok? i want to order by Field, not working, mysql
webmasters
@webmasters: Yes, the syntax is fine in my example (I've tested it locally and it gives the correct results). Are you sure that the syntax you are using is correct?
Mark Byers
A: 

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.

Simon