更新(选择...)设置...

问题描述 投票:0回答:3

我想更新通过 SELECT 语句返回的表的结果。

所以我想:

UPDATE (SELECT [a bunch of joins etc.]) SET thisRecord = 1 WHERE [blah blah]

这对我来说似乎根本不起作用。

任何帮助将不胜感激。

mysql sql nested sql-update
3个回答
2
投票

尝试:

UPDATE Table1
SET column1 = t2.Column
FROM  table1 t1
JOIN (SELECT ... FROM ... lots of joins etc) t2
ON t1.id = t2.otherid

2
投票

如果我很好地理解你的问题,这就是你想要做的:

UPDATE your table name SET thisRecord = 1
WHERE your_criteria = (SELECT [a bunch of joins etc.])

1
投票

文档说明了一切。你不能按照你的想法去做。 然而,你能做的就是翻译你内心的选择

SELECT [a bunch of joins etc.]

应用于要更新的表的条件。

© www.soinside.com 2019 - 2024. All rights reserved.