Adding a new Column from a separate Table...

[expired user #6302]'s profile image [expired user #6302] posted 12 years ago in General Permalink
Is there an easy way to merge data from one table to another?

Need to ADD a 'whole' Column from a one Table into different one. They both have a common ID. Is there an easy way to do it with HeidiSQL?

How about a 'part' of the Column only?

Thanks for your help!
ansgar's profile image ansgar posted 12 years ago Permalink
You need to create the column name/type first in the target table. Then you can
select col from table1 into table2

While that does not update anything, but inserts, of course.
ansgar's profile image ansgar posted 12 years ago Permalink
oh, it's too early in the morning. I meant:
insert into table2 (col) select col from table1
[expired user #6302]'s profile image [expired user #6302] posted 12 years ago Permalink
This inserts into end of records. Need to update into current records.../or empty column...so that it would be alongside current records.

Is that what you mean by update? How is that done?
Sorry I'm new to SQL....

Thanks anse!
ansgar's profile image ansgar posted 12 years ago Permalink
In that case you will need an equal identifier column in both tables (let's call it "someuniquekey"):
UPDATE
table1 AS t1, table2 AS t2
SET t1.col=t2.col
WHERE t1.someuniquekey=t2.someuniquekey
[expired user #6302]'s profile image [expired user #6302] posted 12 years ago Permalink
Thanks anse!!! Just what I needed, a happy camper ={:-))
& you make it look so easy....

Please login to leave a reply, or register at first.