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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with running updates on joined tables

Status
Not open for further replies.

throwdini

Technical User
Oct 20, 2000
37
US
If I have two tables (A and B) joined on the primary key and I want to update a field in table B based on criteria in table A, is there any way to do this?

Any help is greatly appreciated.
Thanks,
Jay
 
Something like:
UPDATE tableB set thing = 'value' where tableB.id = tableA.id and tableA.something = 'whatever';
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
My understanding was that mysql didn't support multi-table updates. I will try the method you mention, but have you successfully done it this way in mysql?

Also, I believe that it is possible to accomplish this kind of multi-talbe update through MS access. Why would it work with the ODBC drivers and access, but not work directly in mysql?

Thanks for the suggestion. Anything else will also be appreciated.
 
Its not possible in mySQL and its not standard SQL to be able to do update based on values in another table. You have to do it programmaticaly or if it is a one time shoot:

do a select that makes up the correct update statements, like:

select 'update tableB set thing = ' ||
a.value ||
' where id = ' ||
b.id ||
';'
from tablea a,
tableb b
where a.id = b.id;

now you will get a lot of update statements in the result. Copy and paste it and run the updates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top