Bug #37185 | last_insert_id() returns all rows (of one value) instead of one row of one value | ||
---|---|---|---|
Submitted: | 4 Jun 2008 9:29 | Modified: | 4 Jun 2008 9:43 |
Reporter: | Nigel Hill | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: General | Severity: | S5 (Performance) |
Version: | 5 | OS: | Windows |
Assigned to: | CPU Architecture: | Any | |
Tags: | LAST_INSERT_ID |
[4 Jun 2008 9:29]
Nigel Hill
[4 Jun 2008 9:34]
Domas Mituzas
LAST_INSERT_ID() is not per-table aggregate function, but global-scope one.
[4 Jun 2008 9:37]
Paul DuBois
To amplify on the last comment: SELECT LAST_INSERT_ID() FROM table_name will always return one row per table. This is not what you want. LAST_INSERT_ID() is not specific to a table, it's specific to the final AUTO_INCREMENT value, so you don't want your second query, either. Just use this: SELECT LAST_INSERT_ID();
[4 Jun 2008 9:43]
Nigel Hill
That explains why the error has never appeared previously to me. This was code from another developer and you are right it is absolutely is an error in the request.