How it works.
First, we created a new table named tbl for testing. In the tbl table, we set AUTO_INCREMENT attribute for the id column.
Second, we inserted a new record into the tbl table.
Third, we used MySQL LAST_INSERT_ID function to obtain last insert id that MySQL has been generated.
It’s important to note that if you insert multiple records into a table using a single INSERT statement, the LAST_INSERT_ID function will return the last insert id of the first record. Suppose the AUTO_INCREMENT column has the last sequence number 3 and you insert 5 records into the table, when you use the LAST_INSERT_ID function to get the last insert id, you will get 4 instead of 8.
Let’s take a look at the following example:
How it works.First, we created a new table named tbl for testing. In the tbl table, we set AUTO_INCREMENT attribute for the id column.Second, we inserted a new record into the tbl table.Third, we used MySQL LAST_INSERT_ID function to obtain last insert id that MySQL has been generated.It’s important to note that if you insert multiple records into a table using a single INSERT statement, the LAST_INSERT_ID function will return the last insert id of the first record. Suppose the AUTO_INCREMENT column has the last sequence number 3 and you insert 5 records into the table, when you use the LAST_INSERT_ID function to get the last insert id, you will get 4 instead of 8.Let’s take a look at the following example:
การแปล กรุณารอสักครู่..
