Reputation: 735
I have the following query :
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)
Now my task is to optmize this query.
I believe removing the exists clause or combining both the where clauses would help a lot. But how to do it ?
PS : exists clause is in place because I want the number of rows updated to be zero if the select clause returns zero rows.
Upvotes: 0
Views: 13574
Reputation: 2041
you can use IN keyword
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)
refer below links:
Upvotes: 0
Reputation: 79889
JOIN
the two tables instead of EXISTS
. Something like the following:
UPDATE tab1
INNER JOIN tab2 ON --some join condition
SET sbd = --something
AND abc = --other something
WHERE --some conditions
Upvotes: 2