- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What would be the effect on the output of MySQL LAST_INSERT_ID() function in the case on multiple-row insert?
152 Lectures 16 hours
87 Lectures 5.5 hours
As we know that MySQL LAST_INSERT_ID() function returns the latest generated sequence number but in case of multiple row-insert it would return the sequence number generated by the foremost inserted row.
mysql> Insert into Student(Name) values('Ram'),('Mohan'),('Aryan'); Query OK, 3 rows affected (0.03 sec) Records: 3 Duplicates: 0 Warnings: 0
The query above inserts three values in Student table with the help of Multiple-row insert query. The value of Column ‘Id’ can be checked with the help of the following query −
mysql> Select * from Student; +----+-------+ | Id | Name | +----+-------+ | 1 | Raman | | 2 | Rahul | | 3 | Ram | | 4 | Mohan | | 5 | Aryan | +----+-------+ 5 rows in set (0.00 sec)
It means that Last_Insert_Id() must return 5 as output but as we can see it returns the value 3 as follows −
mysql> Select Last_Insert_Id(); +------------------+ | Last_Insert_Id() | +------------------+ | 3 | +------------------+ 1 row in set (0.00 sec)
It returns the value 3 because 3 is the value of foremost inserted row with above multiple row-insert query.
- What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL ROUND() function?
- What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL TRUNCATE() function?
- What is MySQL STRCMP() function and what would be the output of this function?
- What would be the effect on MySQL output if we have the combination of NULL and other values in the list of strings, provided as arguments in FIELD() function?
- What would be the result on concatenating server_id and UUID in MySQL?
- MySQL: Insert a row and get the content?
- In function INSERT(str, Pos, len, newstr), what would be the result if ‘Pos’ is not within the length of the string?
- Get the new record key ID from MySQL insert query?
- Correct MySQL INSERT ... ON DUPLICATE KEY syntax?
- In function INSERT(str, Pos, len, newstr), what would be the result if ‘len’ is not within the length of the rest of string?
- What would be the output of MySQL ELT() function if the index number, provided as an argument, is not an integer?
- What is the use of MySQL IGNORE INSERT statement?
- What MySQL returns on running the INSERT INTO statement without giving the column name and values both?
- Update MySQL table on INSERT command with triggers?
- MySQL query to concatenate all the values in each row based on the common matching ID