Link to home
Start Free TrialLog in
Avatar of breeze351
breeze351

asked on

Update from TABLE-A to TABLE-B

I need to update data from TABLE-A to TABLE-B.  I have the correct query for TABLE-A.  Is there a quick way do this without set.
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

INSERT INTO table-b
SELECT * FROM table-a;

HTH,
Dan
Avatar of breeze351
breeze351

ASKER

That would work for an INSERT, but what about UPDATE
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania 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
IIRC MySQL has REPLACE INTO that might do what you want.  I'm not sure what DB you're using, but this is not really a PHP question.
As far as I remember a REPLACE INTO does a delete and insert - if you have auto id's they will change. (http://dev.mysql.com/doc/en/replace.html). ON DUPLICATE KEY does not do this.

However if the intention here is to save some typing on the SET commands it might be better to write a wrapper function that simply takes an array of data and converts it into a SET query.

Let us know if that is the motivation and we can post code.