View Single Post

   
  #5 (permalink)  
Old 02-28-2008, 07:57 AM
TB
 
Posts: n/a
Default Re: adding a column with data

It worked perfectly.

Thanks a lot!

TB


Peter H. Coffin wrote:
> On 21 Jul 2006 05:51:22 -0700, TB wrote:
> > Thanks for replying. The truth is I can actually add another column to
> > the table 'extratable' which contains the same unique values as are
> > being used in the primary key column in 'maintable'
> >
> > I would therefore have:
> >
> > maintable:
> > ID (PK) (int 11)
> > firstname (varchar 40)
> > lastname (varchar 40)
> > phone (varchar 20)
> > fax (varchar 20)
> >
> > extratable
> >
> > ID (int 11)
> > cellphone (varchar 20)
> >
> > I can make ID the PK of extratable.
> >
> > Does that change the situation?

>
> That makes it easy. You first alter the table to add the column to house
> the data you want to add, then update that coloumn to contain the value
> of the other table.
>
> ALTER TABLE maintable
> ADD cellphone VARCHAR(20) AFTER fax;
>
> UPDATE maintable JOIN extratable ON maintable.id = extratable.id
> SET maintable.cellphone = extratable.cellphone;
>
> I haven't tested the above, but that should give you the idea.
>
> --
> 81. If I am fighting with the hero atop a moving platform, have disarmed him,
> and am about to finish him off and he glances behind me and drops flat, I
> too will drop flat instead of quizzically turning around to find out what
> he saw. --Peter Anspach's list of things to do as an Evil Overlord


Reply With Quote