这是一个挑战: 我有三张桌子。 我需要使用查询结果填充table_1。 此查询的输入是table_1的id。我怎么能这样做?
谢谢。
我已经尝试了
UPDATE table_1 AS a
INNER JOIN
(
SELECT s.some_name
FROM table_2 as st
JOIN table_3 AS s ON s.a_id = st.a_id
ORDER BY st.somefiled DESC
LIMIT 1
) AS b ON a.a_id = b.a_id AND a.t_id = b.t_id
SET a.some_name = b.some_name
但是这给了我错误
1054 - 'on子句'中的未知列'b.a_id' 虽然,a_id存在于table_2和table_3
中
提前谢谢
答案 0 :(得分:0)
您还必须在选择列表中显示Id列。像这样的事情: -
UPDATE table_1 AS a
INNER JOIN
(
SELECT s.some_name, st.a_id, st.t_id
FROM table_2 as st
JOIN table_3 AS s ON s.a_id = st.a_id
ORDER BY st.somefiled DESC
LIMIT 1
) AS b ON a.a_id = b.a_id AND a.t_id = b.t_id
SET a.some_name = b.some_name
我不知道这是否能解决你的目的。但这将删除错误