Home » SQL & PL/SQL » SQL & PL/SQL » Basic Update question
Basic Update question [message #23520] Sat, 14 December 2002 08:13 Go to next message
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 Go to previous message
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.
Previous Topic: Update Set of Records
Next Topic: primary key then index necessary?
Goto Forum:
  


Current Time: Thu May 16 01:51:22 CDT 2024