I'm new to (My)SQL and need some help: In a database I have 3 tables, an example:
purchases:
id model price ------------ 1 1 2500 2 2 14000
manufacturer:
id name ----------- 1 Opel 2 Crysler
model:
id name manufacturer ------------------------- 1 Astra 1 2 C 300 2
In the table purchases model is a foreign key and is linked to model.id. In model manufacturer is a foreign key and is linked to manufacturer.id.
My aim is a table which looks like below:
id model price manufacturer ------------------------------ 1 Astra 2500 Opel 2 C300 14000 Chrysler
I know how to do a JOIN in the table purchases to get the model's name. Unfortunately I don't know how to get the manufacturer?
My SQL-query:
SELECT * FROM purchases JOIN model ON purchases.model = model.id