Which function should be used to find the query ID of the second query executed in a current session?
Which function should be used to find the query ID of the second query executed in a current session?
To find the query ID of the second query executed in the current session, you should use LAST_QUERY_ID(2). Positive numbers in the parameter represent the sequence starting from the first query executed, hence LAST_QUERY_ID(2) correctly retrieves the ID of the second query.
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. Etc. 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. Etc.
LAST_QUERY_ID(2) returns the second query LAST_QUERY_ID(-2) returns the second most recently-executed query
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. https://docs.snowflake.com/en/sql-reference/functions/last_query_id#usage-notes
Correct Answer is D. LAST_QUERY_ID(2) returns the second query LAST_QUERY_ID(-2) returns the second most recently-executed query
correct
Should be A, tested in Snowflake.
Incorrect, its D