# MD_LAST_QUERY_ID


> Use MD_LAST_QUERY_ID() to get the UUID of the most recent query sent to MotherDuck.

`MD_LAST_QUERY_ID()` is a scalar function that returns the UUID of the most recent query sent to the MotherDuck server from the current DuckDB [connection](/key-tasks/authenticating-and-connecting-to-motherduck/connecting-to-motherduck/#create-a-connection). This is the same `QUERY_ID` that appears in the [`QUERY_HISTORY`](../md_information_schema/query_history.md) and [`RECENT_QUERIES`](../md_information_schema/recent_queries.md) views.

The function returns `NULL` if no query has been sent to the server yet on the current connection.

## Syntax

```sql
SELECT MD_LAST_QUERY_ID();
```

## Return type

`UUID`: the unique identifier of the last query, or `NULL` if no server-side query has been run.

## Example usage

### Get the ID of your last query

```sql
SELECT MD_LAST_QUERY_ID();
```

### Look up details for last query from this connection in the query history

```sql
SELECT *
FROM MD_INFORMATION_SCHEMA.QUERY_HISTORY
WHERE QUERY_ID = MD_LAST_QUERY_ID();
```


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fmotherduck-sql-reference%2Fconnection-management%2Flast-query-id%2F&page_title=MD_LAST_QUERY_ID&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
