Re: Update rows when in other table
From: Laconic2 <laconic2_at_comcast.net>
Date: Wed, 26 May 2004 08:32:08 -0400
Message-ID: <R6ydncJ_nqpmECndRVn-gg_at_comcast.com>
Date: Wed, 26 May 2004 08:32:08 -0400
Message-ID: <R6ydncJ_nqpmECndRVn-gg_at_comcast.com>
"elziko" <elziko_at_NOTSPAMMINGyahoo.co.uk> wrote in message
news:40b468a8$0$7727$afc38c87_at_news.easynet.co.uk...
> I have two tables TAB_A and TAB_B. I want to update COL_1 in TAB_A to a
> certain value but only for rows where the value COL_2 in TAB_A is also
found
> in COL_2 of TAB_B.
Try this instead:
UPDATE tab_a a
SET col_1 = 'NEWVALUE'
WHERE EXISTS (SELECT 1
FROM tab_b b WHERE a.col_2 = b.col_2) AND col_1 IS NULL;
It only references tab_a once rather than twice. Received on Wed May 26 2004 - 14:32:08 CEST