
Answer-first summary for fast verification
Answer: Select LAST_QUERY_ID(-2)
The question asks for the function to retrieve the query ID of the second most recent query executed in the current session. According to Snowflake documentation and the community discussion (with multiple upvoted comments confirming this), LAST_QUERY_ID() with negative numbers starts from the most recent query: LAST_QUERY_ID(-1) returns the most recent query, and LAST_QUERY_ID(-2) returns the second most recent query. Option A (LAST_QUERY_ID(-2)) correctly matches this requirement. Option B (LAST_QUERY_ID(-1)) retrieves the most recent query, not the second most recent. Options C and D (LAST_QUERY_ID(1) and LAST_QUERY_ID(2)) use positive numbers, which start from the first query in the session, making them unsuitable for retrieving recent queries.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.