copy field from one table to another php

0

Hi, I would like to know how I can finish in a good way the insertion of a field that is already inserted in another table, in this new one, I have what I will show next:

$copcod = mysqli_query("insert into tabla_destino (select id, código from 
tabla_emisora where id=id)");

(where id has to be that of the current session and at the same time that of the original table)

    
asked by Tondrax 10.07.2018 в 10:16
source

1 answer

0

The correct statement for an INSERT with SELECT is as follows

INSERT INTO tabla1 (tabla1_campo1, tabla1_campo2,...)
SELECT tabla2_campo1, tabla2_campo2,... FROM tabla2
WHERE condiciones

It is important to know that data types should be the same or at least compatible.

For example, this insert would fail if table1_field1 were of type INTEGER and table2_field1 were of type CHAR.

So, it is important to check the order of the fields to match the columns.

It is also possible to use some conversion function and thus insert numbers as characters. But if you need such a thing, let us know. For now, try using this syntax, checking the columns and the order you put in the INTO part and the SELECT part.

    
answered by 28.07.2018 в 11:45