I have 3 tables – users, purchases and users_purchases. To connect purchases and users, we need an id from the purchase table, as well as an id from the users table. In order to find out the generated id in MySQL, the only solution is to use the LAST_INSERT_ID function. Let’s say we have code that looks like this:
INSERT INTO purchases VALUES(...);
INSERT INTO purchases_users(id_user, id_purchase) VALUES(1, LAST_INSERT_ID())`
But what if, at the time of adding a purchase row, a new user is added, and after that the LAST_INSERT_ID function is called. Will there be a user ID or purchase ID there?
Perhaps it would not hurt me to go deeper into sql theories, but still I did not find a specific answer with a similar example