我对如何使用where将列从一个表复制到另一个表感到困惑。我编写了SQL查询,但它说超出事务锁定时间或查询返回多行
使用mysql
基本上,
我有:
Table 1: Results
BuildID platform_to_insert
Table 2: build
BuildID correct_platform
update results set results.platform_to_insert
= (select correct_platform from
build where results.BuildID = build.BuildID)
答案 0 :(得分:70)
我认为你不需要子查询。
UPDATE results, build
SET results.platform_to_insert = build.correct_platform
WHERE results.BuildID = build.BuildID
答案 1 :(得分:5)
这里有两个选项:
BuildID
作为主键(以避免重复)更新子查询只返回一个结果
UPDATE results SET results.platform_to_insert = (
SELECT correct_platform
FROM build
WHERE results.BuildID=build.BuildID LIMIT 1
);