Frenda
Frenda

Reputation: 57

MySQL: Is it okay when three proses simultaneusly (INSERT, SELECT, INSERT)?

I have table Context and Criteria with many-to-many relationship, so I created DetailsContext table that stored ID from each table.

Then, Context table is empty and Criteria is master table

I have form to insert a context, firstly I inserted Context table to get an ID (autoincrement) than I selected ID table Context and Criteria by order ID DESC to get latest ID. Then I inserted to DetailsContext table.

Is't ok I just use SELECT ID FROM CONTEXT ORDER BY ID DESC to get latest ID? I afraid it didn't work when many users is accessed together.

Upvotes: 1

Views: 62

Answers (1)

Trott
Trott

Reputation: 70075

If I understand your question correctly, then according to MySQL documentation, you can get the last ID that was inserted into the table with SELECT LAST_INSERT_ID() as long as the id is autogenerated and you are inserting one row per INSERT statement.

Upvotes: 1

Related Questions