我在MySQL中遇到了问题。
SELECT table1.column1, test.column2
FROM table1,table2 AS test
INNER JOIN table3 ON table3.column3 = table1.column1
WHERE test.column2 = table1.column1
我收到此错误:
'on clause'
中的未知列'table1.column1'
答案 0 :(得分:2)
连接表有两种方法:
使用其键在每个表上使用INNER JOIN:
SELECT table1.column1,test.column2
FROM table1
INNER JOIN table2 test
ON table1.column1=test.column2
INNER JOIN table3
ON test.column2=table3.column3
第二个是旧的,它列出FROM子句中的每个表,然后在WHERE子句中链接它们,如:
SELECT table1.column1,test.column2
FROM table1,table2 test, table3
WHERE table3.column3=table1.column1 AND test.column2=table1.column1
答案 1 :(得分:0)
如果在FROM中使用少量表,则必须使用():
from (table1,table2)
答案 2 :(得分:0)
您的查询可以像下面一样进行修改:
Select t1.column1, test.column2
from table1 as t1
join table2 as test on test.column2 = t1.column1
join table3 as t3 on t3.column3 = t1.column1
这里t1,test,t3是表别名