mysql - 查询三个表

Mar*_*ark 2 mysql database join relational

我有一个有三个表的关系数据库.第一个包含与第二个相关的id.第二个包含与第三个相关的id.第三个包含我追求的结果.

是否可以使用单个查询来查询第一个表中的id,该表给出了与第三个表相关的所有结果?

对不起,我是mySQL的新手.

Pet*_*ist 9

Mysql加入

试试这个

select * from table1 t1
join table2 t2 on t1.t2ref = t2.id
join table3 t3 on t2.t3ref = t3.id
Run Code Online (Sandbox Code Playgroud)

添加where子句以搜索table1中的某些行

where t1.field = 'value'
Run Code Online (Sandbox Code Playgroud)


Rik*_*ood 5

是的

SELECT t3.* 
  FROM t1, t2, t3
  WHERE t1.id = t2.id
    AND t2.otherid = t3.id
    AND t1.id = XXXX
Run Code Online (Sandbox Code Playgroud)