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 :
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 ?????
CodePudding user response:
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;