Skip navigation links

MySQL Forums :: PHP :: A tricky (for me) order by 2 colums in 2 tables


Advanced Search

A tricky (for me) order by 2 colums in 2 tables
Posted by: Dave Mante ()
Date: October 10, 2012 10:35AM

Hi guys :)

I have a spectacular (like hell) query where i have to order rows by 2 coulums on 2 different tables but it's tricky. Let me explain:

This is the structure of table_city:

CITY ORDER ZONEID
Milan 1 1
Rome 2 2
Naples 3 3
Venice 4 1

And this is the structure of table_location:

ZONEID ZONE ORDER
1 South 3
2 Center 2
3 North 1

I want to order records first by zone (North -> 1, Center -> 2, South -> 3) and then by city (Milan -> 1, Rome -> 2, Naples -> 3, Venice -> 4). In short i'm looking for this output:

Milan
Venice
Rome
Naples

I tryed with an incredible number of GROUP BY, ORDER BY, SELECT DINSTINCT and even with a SELECT nested in another SELECT but all i can get is a list ordered by zone or city. Not both. Any idea? Am i forced to use 2 queries?

Thank you for your time
Bye

Options: ReplyQuote


Subject Written By Posted
A tricky (for me) order by 2 colums in 2 tables Dave Mante 10/10/2012 10:35AM
Re: A tricky (for me) order by 2 colums in 2 tables Barry Galbraith 10/10/2012 10:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.