MySql使用另一个表中的数据更新一个表

MySql使用另一个表中的数据更新一个表,mysql,sql,sql-update,Mysql,Sql,Sql Update,我有两张结构相同的桌子表1保存已审核的数据,表2保存其余数据 表1 +------+--------+---------------+--------+-----------+ | "id" | "name" | "description" | "type" | "country" | +------+--------+---------------+--------+-----------+ | "1" | "a" | "x" | "1" | "US"

我有两张结构相同的桌子<代码>表1保存已审核的数据,
表2
保存其余数据

表1

+------+--------+---------------+--------+-----------+ | "id" | "name" | "description" | "type" | "country" | +------+--------+---------------+--------+-----------+ | "1" | "a" | "x" | "1" | "US" | | "2" | "b" | "x" | "1" | "UK" | +------+--------+---------------+--------+-----------+ 事情是这样的:

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
剩余条件放在哪里。您能帮忙吗?

将其作为联接,将id放入联接条件中,只需在WHERE子句中检查id即可

大概是这样的:-

UPDATE table1 dest INNER JOIN table2 src ON dest.id = src=id
SET dest.name = src.name, dest.description = src.description 
WHERE dest.id=1 ;
任何其他限制都可以添加到WHERE子句

我认为您可以使用查询根据表2中的数据更新表1,并将您的条件放入WHERE子句中

UPDATE table1 a
INNER JOIN table2 b
ON a.id = b.id
SET a.name = b.name,
a.description = b.description
WHERE a.id=1;

您可以使用连接条件查看此链接,这可能会有所帮助
UPDATE table1 dest INNER JOIN table2 src ON dest.id = src=id
SET dest.name = src.name, dest.description = src.description 
WHERE dest.id=1 ;
UPDATE table1 a
INNER JOIN table2 b
ON a.id = b.id
SET a.name = b.name,
a.description = b.description
WHERE a.id=1;