MySql Join 3 Tables?

Hi Everyone,

How would I go about joining 3 tables at once? My database design/setup is at the below URL. I want the mysql statement to say “1992 Ford Explorer”

http://whatsmyowncarworth.com/class-work/sign3/database/database-display.php

Thanks Everyone!

Here you can read about joins.

If you post the query you’ve got, we can see where you’re going wrong.

Hey Guido2004,

Thanks for the reply. I’m reading your link currently.

These are my sql commands. Please advise.

SELECT car_years.name, car_makes.name
FROM car_makes, car_years
WHERE car_years.id=car_year_id

year, make

>>>>>>>

SELECT car_makes.name, car_models.name
FROM car_makes, car_models
WHERE car_makes.id=car_make_id

make, model

>>>>>>>>

SELECT car_years.name, car_models.name
FROM car_years, car_models
WHERE car_years.id = car_year_id

SELECT years.name, models.name
FROM car_years AS years, car_models AS models
WHERE years.id = car_year_id

year, model

If you’re joining on something called year_id, I think something’s gone very wrong!
I would expect to see something more along these lines

makes(make_id*,make)
models(make_id*,model_id*,model) [also (`make_id`,`model`) should be unique]
model_year(model_id*,year*)

* = PRIMARY KEY (or component thereof)

SELECT k.make
     , d.model
     , y.year
  FROM makes k
  JOIN models d
    ON d.make_id = k.make_id
  JOIN model_year y
    ON y.model_id = d.model_id;