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

update tbl X using data from table Y

Status
Not open for further replies.

JMPS

Programmer
Jul 4, 2001
6
GB
Hello!

In table X I need to update every row in a column using data from columns in table Y.

Is there any clean way to do it in mySQL? Since UPDATE seems accept no joins, I can only imagine two solutions: Either I make a script to do the job column by column (one UPDATE command for each column), or I make an empty copy of the table that I want to modify, fill it with INSERT ... SELECT and drop the old table. Any of these solutions look very, very, very bad for big tables...

What am I missing?

Thanks,
jmps
 

Hi, did you get a response to this, i'm looking at the same problem?

cheers
Rich
 
Hi guys,

I've got the same problem now. Any suggestion??

update t1, t2
set t1.txt = t2.txt
where t1.id = t2.id;

I've tried this code in Access and it did work well but not for MySQL at all.
 
Try this - it's not pretty, but might be what you need:
Code:
CREATE TABLE temptable
SELECT
tabletoupdate.ID,
tabletoupdate.nochangecol,
tableupdatefrom.changecol
FROM tabletoupdate
INNER JOIN tableupdatefrom ON tabletoupdate.ID=tableupdatefrom.ID;

DROP TABLE tabletoupdate;

RENAME TABLE temptable TO tabletoupdate;

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top