MySQL Forums
Forum List  »  Newbie

use max(id) from table to insert in other table
Posted by: leandro roggerone
Date: May 15, 2018 06:42AM

Hi guys , I have 3 tables with auto generated incremental ids.

This is what I would like to achieve:

INSERT INTO mqtt_connection (broker_ip,broker_port,broker_user,broker_pass, topic)
            VALUES('mqtt.controller.com.ar','83','pmmc','pmmc1234','topic-seed')


INSERT INTO rtu (rtu_id, connection_id, mac, client_id_mosquitto, service_status)   VALUES('rtussltest',select max(id) from mqtt_connection,'b827eb8ec0c3','saraza1234saraza5678','active');


INSERT INTO user (user_id, connection_id, rtu_id, client_id_mosquitto, user_name, user_pass, service_status)
VALUES('usuario00001',select max(id) from mqtt_connection,select max(id) from rtu,'saraza4321saraza8765','ssl_user ','1234','active' )

the
select max(id) from mqtt_connection,select max(id) from rtu
is the sentense that does not work.
Is there some way to get the last generated ids from table to insert in another table ?
Regards;
Leandro.

Options: ReplyQuote


Subject
Written By
Posted
use max(id) from table to insert in other table
May 15, 2018 06:42AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.