Basic Update question [message #23520] |
Sat, 14 December 2002 08:13 |
Reddy Peram
Messages: 52 Registered: December 2002
|
Member |
|
|
UPDATE tableA A set (col1,col2,...col10) = (SELECT col1,col2,col3..col10 FROM tableB B
WHERE B.KEY1 = A.KEY1
AND B.Key2 = A.Key2);
-----------------------------
UPDATE tableA A set (col1,col2,...col10) = (SELECT col1,col2,col3..col10 FROM tableB B
WHERE B.KEY1 = A.KEY1
AND B.Key2 = A.Key2)
where exists
SELECT null FROM tableB B
WHERE B.KEY1 = A.KEY1
AND B.Key2 = A.Key2;
Are both these update statements same?
|
|
|
Re: Basic Update question [message #23531 is a reply to message #23520] |
Sun, 15 December 2002 16:07 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
No, they are not.
Statement #1 will update every row in tableA regardless of whether a matching row in found in tableB. Rows with no match will have the listed columns updated to a NULL value.
Statement #2 will only update the rows that have a matching row in tableB.
|
|
|