mysql - query three tables

后端 未结 5 1419
庸人自扰
庸人自扰 2021-01-22 19:06

I have a relational database with three tables. The first containts id\'s that relate to the second. The second contains id\'s that relate to the third. The third contains the r

5条回答
  •  盖世英雄少女心
    2021-01-22 19:57

    you want to use a join:

       SELECT `t3`.`id`
         FROM `table3` `t3`
    LEFT JOIN `table2` `t2`
           ON `t3`.`foreign_id` = `t2`.`id`
    LEFT JOIN `table1` `t1`
           ON `t2`.`foreign_id` = `t1`.`id`
        WHERE `t1`.`id` = 'some_id'
    

提交回复
热议问题