Fill MYSQL table with another table from the same database where table A has 1 field more than table B

-1

As the question says, both tables are in the same database and both have the same fields (such as telephone address name etc ...) with the difference that table A (original table containing the data) has 1 field more than table B (table where the data goes) field that in table B is not necessary and should not be copied

  

INSERT INTO file (FILE, NOMPAC, DATE, AGE_A, EDAD_M, SEX, ADDRESS, CITY, TEL, CODSER, CHANNEL, CODDOC, KEY, KEY2, KEY3, cie10) SELECT * FROM dead WHERE RECORD = '0481/02 ';

for example with that statement I transfer all the information of the dead table (for this example it will be table A) and all inserting it to the table file (table B for this example)

This is the image of table B the fields it contains

And this is the image of the table A as you will see they have all the same fields with the exception of the field CODCAUSA which is precisely the field that I do not want nor should I go to table B

and this is the error that I get, which is quite clear, the problem is the column CODCAUSA that does not exist inside the table B and it should not exist then is there any way to exclude that data when inserting? Likewise, the same record transferred from table A to table B will be deleted so that the same data will be lost.

  

Error Code: 1136. Column count does not match value count at row 1

    
asked by Diego Pineda Cervantes 20.08.2018 в 15:46
source

2 answers

1

You must indicate which columns you want to add to the table B to the statement SELECT by replacing the operator * with the name of the columns

INSERT INTO archivo(EXPEDIENTE,NOMPAC,FECHAINGRE,EDAD_A,EDAD_M,SEXO,DIRECCION,CIUDAD,TEL,CODSER,CANALIZO,CODDOC,CLAVE,CLAVE2,CLAVE3,cie10) SELECT EXPEDIENTE,NOMPAC,FECHAINGRE,EDAD_A,EDAD_M,SEXO,DIRECCION,CIUDAD,TEL,CODSER,CANALIZO,CODDOC,CLAVE,CLAVE2,CLAVE3 FROM muerto WHERE EXPEDIENTE ='0481/02';
    
answered by 20.08.2018 / 15:56
source
0

Try changing the "*" of the SELECT, specifying the attributes you want to select. If I'm not mistaken, it would be something like that.

INSERT INTO archivo(EXPEDIENTE,NOMPAC,FECHAINGRE,EDAD_A,EDAD_M,SEXO,DIRECCION,CIUDAD,TEL,CODSER,CANALIZO,CODDOC,CLAVE,CLAVE2,CLAVE3,cie10) SELECT EXPEDIENTE,NOMPAC,FECHAINGRE,EDAD_A,EDAD_M,SEXO,DIRECCION,CIUDAD,TEL,CODSER,CANALIZO,CODDOC,CLAVE,CLAVE2,CLAVE3,cie10 FROM muerto WHERE EXPEDIENTE ='0481/02';
    
answered by 20.08.2018 в 16:32