how to get a specifique ID only with mysql

I’m looking for something can help me to get the id of the ticket created at the first row.

I know i can simplify this by using different prepared query but I want not (try and see if it possible by this way and if it’s not using the multiple queries way.

I know LAST_INSERT_ID() in mysql but I’m a little worried about inserting several lines at the same time….

During my research I also see someone directy SELECT the specified ID but it’s a big cost of ressources.

I also see @@INSERTED and i didn’t see a big difference between them, so i had the same problem…

The code :

CREATE PROCEDURE `Create_Ticket`(IN idU bigint(16),IN type VARCHAR(45),IN pseudo VARCHAR(45), IN lienacc VARCHAR(100), IN liengame VARCHAR(100), IN content VARCHAR(500))
BEGIN
    INSERT INTO `dbOneT`.`Ticket` (`FaceitGame`,`Status`,`Ouverture` ) 
        VALUES ( liengame , 0 , NOW());
    INSERT INTO `dbOneT`.`Users_has_Ticket` (`Users_id`, `Ticket_id`) 
        VALUES ( idU, `Ticket`.`idTicket` );
    INSERT INTO `dbOneT`.`Accuse` (`Pseudo`,`LienFaceit`) 
        VALUES (pseudo, lienacc);
    INSERT INTO `dbOneT`.`Ticket_has_Accuse` (`Ticket_id_A`, `Accusé_id`) 
        VALUES (`Ticket`.`idTicket`, `Accuse`.`idAccuse`);
END

I’m running MariaDB 10.3.27

The “computer” is a raspberry pi 4B with 8go ram
On Raspberry Pi OS (A debian)

thanks for your help and have a nice day
Tom

Answer

CREATE PROCEDURE `Create_Ticket`(IN idU bigint(16),IN type VARCHAR(45),IN pseudo VARCHAR(45), IN lienacc VARCHAR(100), IN liengame VARCHAR(100), IN content VARCHAR(500))
BEGIN
-- declare variables for inserted PK AI values
    DECLARE _idTicket INT;
    DECLARE _idAccuse INT;

    INSERT INTO `dbOneT`.`Ticket` (`FaceitGame`,`Status`,`Ouverture` ) 
        VALUES ( liengame , 0 , NOW());
-- save assignerd AI value to the variable
    SET _idTicket := LAST_INSERT_ID();
    INSERT INTO `dbOneT`.`Users_has_Ticket` (`Users_id`, `Ticket_id`) 
-- use saved value
        VALUES ( idU, _idTicket );
    INSERT INTO `dbOneT`.`Accuse` (`Pseudo`,`LienFaceit`) 
        VALUES (pseudo, lienacc);
-- save assignerd AI value to the variable
    SET _idAccuse := LAST_INSERT_ID();
-- use saved values
    INSERT INTO `dbOneT`.`Ticket_has_Accuse` (`Ticket_id_A`, `Accusé_id`) 
        VALUES (_idTicket, _idAccuse);
END