Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MYSQL problem: How to add values from one table to another

I have problem with probably a simple matter:
I want to insert data from one table into another.

TO THIS table :

(ID_autor, name, surname)

FROM THIS :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

autor(ID_autor, name, surname, nationality, birthday)

This is my code :

INSERT INTO tab1 (ID_autor, name, forname)
SELECT ID_autor, name, forname, nationality, birthday
FROM autor;

But I dont know why it is bad ?????

>Solution :

You should only select the columns that have corresponding columns in the destination table. Since there’s no nationality or birthday columns in tab1, leave those out of the select list.

INSERT INTO tab1 (ID_autor, name, forname)
SELECT ID_autor, name, forname
FROM autor;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading