how to select the maximum of one auto increment field and save it in another table

2

I have a record in a table called PARAMETRI that has an autoincrement field named idparametri . What I want to do is save a record in a table called OBRA ; that table has a field called PARAMETRI_ID_PARAMETRI and I want to make a record when I save the maximum value of ID_PARAMETRI in PARAMETRI_ID_PARAMETRI which is the work id, but at the same time I want to insert the other fields in the table OBRA

Here the maximum value of the auto increment is inserted into the table OBRA

INSERT INTO OBRA (PARAMETRI_ID_PARAMETRI) SELECT MAX(PARAMETRI.ID_PARAMETRI) FROM PARAMETRI; 

How do I insert the maximum value of the auto increment and other parameters in the OBRA table that are NOMBRE_O , DIRECCIÓN and VALOR

I hope you can help me.

    
asked by luisa suaza 27.11.2018 в 19:27
source

1 answer

0

To perform the insertion including other fields, use a statement insert / values , and in the value of the field PARAMETRI_ID_PARAMETRI you do the sub-query to obtain the maximum value that interests you, for example:

insert into OBRA (NOMBRE_O, DIRECCION, VALOR, PARAMETRI_ID_PARAMETRI) 
values ('Prueba', 'Dirección', 1.0, (select max (ID_PARAMETRI) from PARAMETRI)); 
    
answered by 27.11.2018 / 23:03
source