Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql exists查询的备选方案_Sql - Fatal编程技术网

Sql exists查询的备选方案

Sql exists查询的备选方案,sql,Sql,我有以下疑问: update tab1.abc, tab1.sbd = (select tab2.abc, tab2.sbd from tab2,tab1 where --some conditions) where exists(select tab2.abc, tab2.sbd from tab2,tab1 where --some conditions) 现在我的任务是选择这个查询 我相信删除exists子句或合并where子句会有很大帮助。 但是怎么做呢 PS:exists子句已就位,

我有以下疑问:

update tab1.abc,
tab1.sbd = (select tab2.abc, tab2.sbd from tab2,tab1 where --some conditions)
where exists(select tab2.abc, tab2.sbd from tab2,tab1 where --some conditions)
现在我的任务是选择这个查询

我相信删除exists子句或合并where子句会有很大帮助。 但是怎么做呢


PS:exists子句已就位,因为如果select子句返回零行,我希望更新的行数为零。

您可以在关键字中使用

update tab1.abc,
tab1.sbd = (select tab2.abc, tab2.sbd from tab2,tab1 where --some  conditions)
where something in 
(select tab2.abc, tab2.sbd from tab2,tab1 where --some conditions)
请参阅以下连结:


连接
这两个表而不是
存在
。如下所示:

UPDATE tab1
INNER JOIN tab2 ON --some join condition
SET sbd = --something
AND abc = --other something
WHERE --some conditions

请包括确切的查询。通过过滤掉
--一些条件
,我们实际上看不到您的查询做了什么以及如何重构它。我不认为这会提高性能,因为我们正在运行同一个查询两次?感谢您的回答,但我从三个表中提取数据进行更新,并检查每个表的一些参数,在这种情况下,加入不是很昂贵吗?