distal-attribute
distal-attribute
distal-attribute
distal-attribute

Adding a new Column from a separate Table...

Ash501 posted 3 years ago in General
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 posted 3 years ago
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 posted 3 years ago
oh, it's too early in the morning. I meant:

insert into table2 (col) select col from table1

Ash501 posted 3 years ago
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 posted 3 years ago
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

Ash501 posted 3 years ago
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.