使用php mysql从五个表中选择

时间:2016-01-29 02:49:42

标签: mysql

我有五张桌子:

  1. table1
  2. table2
  3. table3
  4. table4
  5. 表5
  6. 在这些表中,字段很常见,即name

    SELECT *
    FROM table1, table2, table3, table4, table5
    WHERE table1.name = table2.name
        and table2.name = table3.name
        and table3.name = table4.name
        and table4.name = table5.name
    

    此类查询是否有效?

1 个答案:

答案 0 :(得分:0)

试试这个例子并根据自己的喜好进行调整。

SELECT T1.*, T2.*, T3.*, T4.*, T5.*
FROM TABLE1 T1 
JOIN TABLE2 T2 ON T1.NAME = T2.NAME
JOIN TABLE2 T3 ON T1.NAME = T3.NAME
JOIN TABLE2 T4 ON T1.NAME = T4.NAME
JOIN TABLE2 T5 ON T1.NAME = T5.NAME