On Wed, Dec 04, 2002 at 04:32:35PM -0500, Michael T. Babcock wrote:
> information from "a" to "b".  Any ideas for a one-shot SQL command to do this?
> I'm about to try selecting everything from "b" and the CommID from "a" as a 
> join into a temporary table, then "REPLACE" it back into "b".
 
In case anyone wants to know how to do an UPDATE ... SELECT FROM ...,
I did the equivalent of:

BEGIN;
ALTER TABLE b ADD Col3 ...;

CREATE TABLE CopyCol3
      SELECT b.id, b.Col1, b.Col2, a.Col3 
        FROM b 
   LEFT JOIN a 
          ON a.id = b.id;

REPLACE INTO b (Col1, Col2, Col3) 
      SELECT * 
        FROM CopyCol3;

DROP TABLE CopyCol3;
ALTER TABLE a DROP Col3;
COMMIT;

This was to move the value Col3 from table a to b based on 'id'.

-- 
Michael T. Babcock
CTO, FibreSpeed Ltd.     (Hosting, Security, Consultation, Database, etc)
http://www.fibrespeed.net/~mbabcock/

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to