【问题标题】:How to make 2 different joins in one query (3 tables) on mysql如何在mysql上的一个查询(3个表)中进行2个不同的连接
【发布时间】:2017-04-01 01:22:16
【问题描述】:

假设我有 3 张桌子,我想像这样加入它们:

table 1 join table 2 and table 2 join table 3

我正在尝试以下代码,但出现语法错误。

SELECT * from table1 join table2 and table2 join table3 on table1.id=table2.idA and table2.idB=table3.id

【问题讨论】:

    标签: mysql sql join mariadb


    【解决方案1】:

    学习一下 SQL。语法如下:

    select *
    from table1 join
         table2
         on table1.id = table2.idA join
         table3  
         on table2.idB = table3.id;
    

    这是非常基本的JOIN 语法,应该包含在任何教程、文档、书籍、论文或任何你用来学习 SQL 的东西中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 2019-09-22
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多