LAST_QUERY_ID
Description
Returns the ID of a specified query in the current session. If no query is specified, the most recently-executed query is returned.
Syntax
1. LAST_QUERY_ID( [ <num> ] )
Arguments
num: Specifies the query to return, based on the position of the query (within the session).
Default: -1
Usage Notes
Positive numbers start with the first query executed in the session. For example:
- LAST_QUERY_ID(1) returns the first query.
- LAST_QUERY_ID(2) returns the second query.
- LAST_QUERY_ID(6) returns the sixth query.
Negative numbers start with the most recently-executed query in the session. For example:
- LAST_QUERY_ID(-1) returns the most recently-executed query (equivalent to LAST_QUERY_ID()).
- LAST_QUERY_ID(-2) returns the second most recently-executed query.
Examples
1. mysql> SELECT LAST_QUERY_ID(-1);
2. +--------------------------------------+
3. | last_query_id(-1) |
4. +--------------------------------------+
5. | af974680-b1b5-11ed-8eb9-5ad2460dea4f |
6. +--------------------------------------+
7. 1 row in set (0.00 sec)
9. mysql> SELECT LAST_QUERY_ID();
10. +--------------------------------------+
11. | last_query_id() |
12. +--------------------------------------+
13. | 550e4d44-b1b5-11ed-8eb9-5ad2460dea4f |
14. +--------------------------------------+
15. 1 row in set (0.00 sec)
