Snowpro Core · Free Practice Question Medium
Question 52
Which of the following can be used to find the query ID of the most recent query executed in the current session?
Select two answers.
-
A
SELECT LAST_QUERY_ID(-1);
-
B
SELECT LAST_QUERY_ID();
-
C
SELECT LAST_QUERY_ID(1);
-
D
SELECT LAST_QUERY_ID(-2);
-
E
SELECT LAST_QUERY_ID(2);
Reveal correct answers
Correct answers: A, B
Explanation
The LAST_QUERY_ID function returns the query ID of a specified query in the current session. The function takes a number as the parameter, which specifies the position of the query in the session.
The parameter can take positive or negative values. A negative value means you are attempting to fetch the most recent query in the session, where
-1 = most recent query
-2 = 2nd most recent query
, and so on. The function defaults to -1, so if no value is provided, it will return the query id of the most recent query.
A positive number returns the earliest queries in the session. i.e.
1 = first query
2 = 2nd query
https://docs.snowflake.com/en/sql-reference/functions/last_query_id
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
