Select and insert value from other table

Hi!
I have a problem:
i have this table Kontakt with following columns:
KONTAKTPERS_NAMN,KONTAKTPERS_TELE,KONTAKTPERS_MOBIL,KONTAKTPERS_EMAIL,ADRESS_ID

now i want to insert a new column called PLACE and insert values from an other table called ADRESS witch have following columns:
ADRESS_ID,PLACE

So i need to select the place value from Adress were ADRESS_ID is like ADRESS_ID in Kontakt

Hope you guys understood what i try to do :slight_smile:

So you want to perform a JOIN. Do you still want to send back the KONTAKTPERS_NAMN,KONTAKTPERS_TELE,KONTAKTPERS_MOBIL,KONTAKTPERS_EMAIL, even if there is no address in the ADDRESS table? As that will determine if you use a LEFT or RIGHT JOIN.

If you search for JOIN and the database you are using (MSSQL, MySQL, Postgres, etc) you will quickly find examples on how to write your JOIN.

Hi!
i would make a new table called Contacts with following columns:
KONTAKTPERS_NAMN,KONTAKTPERS_TELE,KONTAKTPERS_MOBIL,KONTAKTPERS_EMAIL,ADRESS_ID,PLACE

But how can i insert the data from the other 2 tables?

Should i use 2 queries in mysql?
Insert * from kontakt were ADRESS_ID like ADRESS_ID

crap i cant understand how to do this :slight_smile:

INSERT INTO Contacts 
SELECT KONTAKTPERS_NAMN, KONTAKTPERS_TELE, KONTAKTPERS_MOBIL, KONTAKTPERS_EMAIL, k.ADRESS_ID, PLACE
  FROM Kontakt AS k LEFT JOIN ADDRESS AS a ON k.ADRESS_ID = a.ADRESS_ID