我有两个结构相同的表。Table1
保存经过审核的数据,table2
保存其余数据。
表格1
+--------+--------+---------------+--------+-------- ---+ | “身份证” | “名字” | “说明” | “类型” | “国家” | +--------+--------+---------------+--------+-------- ---+ | "1" | “一个” | "x" | "1" | “美国” | | "2" | "b" | "x" | "1" | “英国” | +--------+--------+---------------+--------+-------- ---+
表 2
+-----+------------+-----------------+--------+--- --------+----------+ | “身份证” | “名字” | “说明” | “类型” | “国家” | “状态” | +-----+------------+-----------------+--------+--- --------+----------+ | "1" | “标题1” | “说明1” | "1" | “美国” | "0" | | "2" | “标题2” | 《说明2》 | “10” | “英国” | "0" | +-----+------------+-----------------+--------+--- --------+----------+
我运行下面的 sql 以table 1
使用来自 的数据进行更新table 2
,它运行良好。唯一的问题是,我需要id
在两个地方都指定。如果我只在一个地方指定它,它会去哪里?
UPDATE table1 dest,
(SELECT name,
description
FROM table2
WHERE id = 1) src
SET dest.name = src.name,
dest.description = src.description
WHERE dest.id = 1;
这件事的发展方式是:
UPDATE table1 SET name AND description =
(
SELECT name, description from table2
WHERE id=1 AND country=us and type=10
) WHERE id=idfromselect AND country=countryfromselect AND type=typefromselect
我不知道在哪里放id
and remaining conditions
。你能帮我吗?