[英]Mysql left join multiple tables
I have a database which stores information about cars. 我有一个数据库,其中存储有关汽车的信息。 There are 3 tables which don't have foreign keys:
有3个没有外键的表:
make(make_ID, name,..) make(make_ID,名称等)
colour(colour_ID,c_name,...) 颜色(colour_ID,c_name,...)
engine(engine_ID,eng_size,...) 引擎(engine_ID,eng_size,...)
There's a 4th table which connects all the others together using foreign keys(FK): 第四个表使用外键(FK)将所有其他表连接在一起:
carDetails(CarDetails_ID, CD_make_ID, CD_colorID,...) carDetails(CarDetails_ID,CD_make_ID,CD_colorID等)
Now I would like to use left joins to retrieve the appropriate information from tables about a car by using the IDs in the query. 现在,我想使用左联接通过查询中的ID从有关汽车的表中检索适当的信息。
Ideally I would like to select the make.name WHERE make.make_ID = carDetails.CD_make_ID etc. and keep joining extra information on the left. 理想情况下,我想选择make.name WHERE make.make_ID = carDetails.CD_make_ID等,并继续在左侧加入其他信息。 I have tried this and i'm getting errors on the 'where' clause...apparently it cannot be recognized.
我已经尝试过了,并且在'where'子句上出现错误...显然无法识别。
SELECT name FROM make WHERE 'make.make_ID' = 'carDetails.CD_make_ID' LEFT JOIN colour.name WHERE colour.colour_ID = carDetails.CD_colour_ID
What am I doing wrong? 我究竟做错了什么?
尝试这个
SELECT name FROM make, carDetails WHERE 'make.make_ID' = 'carDetails.CD_make_ID' LEFT JOIN colour.name ON colour.colour_ID = carDetails.CD_colour_ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.