我正在尝试加入 part_type_n
上的不同列(Table1
(其中 n 范围从 1 到 54))与 id
上的同一列( Table2
,主要,autoinc) .
架构:
Table1 ============== part_type_1 . . . part_type_54 Table2 ============= id
我尝试了明显的查询(php生成,从1到54循环n),省略了...中的重复内容:
SELECT * FROM Table1 JOIN Table2 on (Table1.part_type_1=Table2.id), ..., (Table1.part_type_54=Table2.id)
我收到此错误:
1066 - 不唯一的表/别名:“Table2”
如何连接这两个表?
最佳答案
您必须多次自行加入该表。
SELECT * FROM table1 t1
INNER JOIN table2 t2 on t2.Id=t1.part_type_1
INNER JOIN table2 t3 on t3.id = t1.part_type_54;
希望这有帮助!
关于MySQL - 连接两个表,表1中的不同列与表2中的同一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19340637/