Link to home
Start Free TrialLog in
Avatar of Algorithmix
AlgorithmixFlag for United States of America

asked on

How to update a table based on the output of a select?

I need to update a table based on the output of a select.
Example:
Select a.fld1, a.fld2 from db.tableA a where a.fld3 = 'blahblah'
The output might be something like
fld1           fld2
'TEXT1'      123
'TEXT2'      432
'TEXT3'       534
etc..

I'd like to be able to update tableB based on the results of this select.

update db.tableB b set b.fld1 = a.fld1 where b.fld2 = a.fld2

how would write such an update command?

i hope i'm  explaining myself clearly - ?
ASKER CERTIFIED SOLUTION
Avatar of joebednarz
joebednarz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of a_twixt_in_the_tale
a_twixt_in_the_tale

you might want to add one more clause to joebednarz's solution
 
... where b.fld2 in (select a.fld2 from tableA)

cheers!
Don
Avatar of Algorithmix

ASKER

Thanks guys!