我需要连接表 1 和表 2。我不知道表 2 的名称,但它是表 1 中的一条记录。所以我正在尝试:
SELECT table2.*
from table1 t
JOIN (
SELECT tname from table1 t1 WHERE t.id = t1.id
) as table2 ON table2.ref = t.ref
WHERE ...
但它不起作用。有任何想法吗?谢谢
我的错误是:“‘where 子句’中的未知列‘t.id’”
最佳答案
您可以将查询修改为如下所示。试一试
SELECT t.*
from table1 t
JOIN (
SELECT id, tname from table1
WHERE some_condition
) table2 on t.id = table2.id
WHERE ...
关于mysql - 加入未知表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26742923/