# Can I use multiple SQL statements in a single MySQL query?

**URL:** <https://community.grafana.com/t/can-i-use-multiple-sql-statements-in-a-single-mysql-query/162821>\
**Category:** MySQL\
**Tags:** query-help\
**Created:** [May 9, 2026, 2:45am UTC](https://community.grafana.com/t/can-i-use-multiple-sql-statements-in-a-single-mysql-query/162821 "2026-05-09T02:45:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![huangsijun17](https://avatars.discourse-cdn.com/v4/letter/h/9fc29f/32.png) [@huangsijun17](https://community.grafana.com/u/huangsijun17)\
**Post date:** [May 9, 2026, 2:45am UTC](https://community.grafana.com/t/can-i-use-multiple-sql-statements-in-a-single-mysql-query/162821/1 "2026-05-09T02:45:25Z")

</div>

- What Grafana version and what operating system are you using?

- **What** are you trying to achieve?

- **How** are you trying to achieve it?

- What happened?

- What did you **expect** to happen?

- Can you copy/paste the configuration(s) that you are having problems with?

- Did you receive any errors in the Grafana UI or in related logs? If so, please tell us **exactly** what they were.

- Did you follow any online instructions? If so, what is the URL?

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [May 9, 2026, 5:52am UTC](https://community.grafana.com/t/can-i-use-multiple-sql-statements-in-a-single-mysql-query/162821/2 "2026-05-09T05:52:53Z")

</div>

Copy that query out of grafana and run in a mysql query tool

What do you see

---

<div class="post-metadata">

**Author:** ![huangsijun17](https://avatars.discourse-cdn.com/v4/letter/h/9fc29f/32.png) [@huangsijun17](https://community.grafana.com/u/huangsijun17)\
**Post date:** [May 9, 2026, 5:56am UTC](https://community.grafana.com/t/can-i-use-multiple-sql-statements-in-a-single-mysql-query/162821/3 "2026-05-09T05:56:59Z")

</div>

1. It works correctly in MySQL client tools.
2. Executing the SQL statements as two separate queries has a chance of successful decryption and a chance of failure. Sometimes refreshing the page can restore functionality.

---

<div class="post-metadata">

**Author:** ![infofcc3](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/infofcc3/32/51248_2.png) [@infofcc3](https://community.grafana.com/u/infofcc3)\
**Post date:** [May 9, 2026, 6:00am UTC](https://community.grafana.com/t/can-i-use-multiple-sql-statements-in-a-single-mysql-query/162821/4 "2026-05-09T06:00:36Z")

</div>

Hi @huangsijun17 ,  
You can’t use two SQL lines in one query it will through the error, so the solution is creating a MySQL stored procedure.  
Inside the procedure, we run both the session setting and the query together:  
For example :-

CREATE PROCEDURE get\_users\_decrypted()  
BEGIN  
SET SESSION block\_encryption\_mode = ‘aes-256-ecb’;

```
      SELECT 
                 id,
                 username,
                 CAST(AES_DECRYPT(email_enc, 'key') AS CHAR) AS email,
                 dept
       FROM users
       ORDER BY id;

```

END;

Then in Grafana, the query becomes:

CALL grafana\_demo.get\_users\_decrypted();

Here is the result -

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/0/b/0b23c0d64829e987fcbadbe1b12bc3be06a5397c.png)  
If you need anything else, please let me know.
