Click to See Complete Forum and Search --> : Syntax for extracting info from multiple tables


Beedge
05-30-2007, 04:27 AM
Hi,

I have 3 tables:

alerts:

id
category
location


category

id
category_name


location

id
location_name


Say the tables are filled:
Alerts
Id = 1
category = 3
location = 2

Category
id = 1
category_name = residential

id = 2
category_name = new developments

id = 3
category_name = agricultural

id = 4
category_name = commercial

Location
id = 1
location_name = Cork

id = 2
location_name = Kerry

id = 3
location_name = Dublin

id = 4
location_name = Limerick



What statement would I use to ouput from the alerts table:

alert_id = 1
category_name = Agriclutural
location_name = Kerry

Ive seen tutorials on using JOIN but Im a bit confused as to how you would join 3 or more tables in the statement.

I dont neccessarily need any one to code this but a good tutorial or link would be appreciated, although if someone wants tell me what the select statement would be thats cool too :)

Thanks

Beedge

Beedge
05-30-2007, 05:26 AM
Just found the Answer in a previous post by Russel:


SELECT * FROM `ph_alerts` as a
inner join `ph_prop_cats` as b on a.category = b.id
inner join `ph_locations` as c on a.location = c.id
WHERE a.id = '$id'

Works like a treat :)