tags:

views:

185

answers:

1

So, I have countries, regions and groups.

countries
|cid|name|
regions
|rid|name|cid|
groups
|gid|name|phone|time|rid|

So how can I select each group with its country and region in order:

eg.

|cname|rname|gname|phone|time|
|Australia|nsw|test|1111|whatever|
|Australia|nsw|test2|110|whatever|
|Australia|vic|test3|100|whatever|
|England|London|tes4|010|whatever|
+4  A: 
SELECT c.name, r.name, g.name 
FROM groups g INNER JOIN regions r ON(r.rid=g.rid) 
    INNER JOIN countries c ON(c.cid=r.cid) 
ORDER BY c.name, r.name, g.name;

This should get you most of the way that you want to go.

I didn't know what you wanted to order by.

James Black
see how it goes Country, state, group in a-z order.
steven
use the ORDER clause and specify the columns and ASC/DESC...
meder
how?.................
steven
something like "SELECT * FROM Google WHERE query = 'sql order by clause'"
SquareCog
I just edited it to answer Steven's order by inquiry. Granted he probably figured it out by now and should have deleted his comments.
dlamblin
@dlamblin - Thank you.
James Black