Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need subquery in SET clause of UPDATE 1

Status
Not open for further replies.

mhoyt

Technical User
Apr 11, 2005
49
US
I have a blank field in one table that I want to update based on information in another table. The tables are related and the subquery in my SET = clause returns the right information, but I get the error that my subquery cannot return more than one value.

How can I relate the list of returned values to the original table so I can update it?

Code:
UPDATE TABLE1
SET LASID = (SELECT TABLE2.STD_NUMBER 
			FROM TABLE2 JOIN TABLE3 
				ON TABLE2.ID = TABLE3.ID
			JOIN TABLE1 
				ON TABLE1.ID = TABLE3.ID)
TIA
 
Try something like this...

Code:
UPDATE TABLE1
SET    TABLE1.LASID = TABLE2.STD_NUMBER
FROM   TABLE2 
       JOIN TABLE3 
         ON TABLE2.ID = TABLE3.ID
       JOIN TABLE1 
         ON TABLE1.ID = TABLE3.ID)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Oh, I need to suggest that you backup your database first. If the query runs and it updates the wrong data, you could end up with a real mess on your hands.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Brilliant! And so prompt. Thank you so much!
(And not bad advice about backing up first either!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top