# How to retry ID from MySQL of last INSERT INTO

**URL:** <https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433>\
**Category:** General\
**Created:** [21 March 2020 18:45 UTC](https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433 "2020-03-21T18:45:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rex](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rex/32/59848_2.png) [@rex](https://discourse.nodered.org/u/rex)\
**Post date:** [21 March 2020 18:45 UTC](https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433/1 "2020-03-21T18:45:03Z")

</div>

I'm able to store int MySQL compiling msg.topics with insert into ... SQL command, but I need to get the ID of this transaction.

How to do?

Thanks, Fabrizio

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 March 2020 19:26 UTC](https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433/2 "2020-03-21T19:26:55Z")

</div>

What do you mean by ID?

---

<div class="post-metadata">

**Author:** ![rex](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rex/32/59848_2.png) [@rex](https://discourse.nodered.org/u/rex)\
**Post date:** [21 March 2020 19:58 UTC](https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433/3 "2020-03-21T19:58:34Z")

</div>

You're right, I wasn't precise.  
In my table, I have a primary key with auto-increment enabled, so when I make "insert into" this field is automatically created.  
I want to retrieve it, contextually with insert command.

I'm not sure I can use :  
SELECT max(id) FROM mytable;

because I have other asynchronous insertion, and the risk is to get bad id from a sequence like this:

1. my Insert
2. other asynchronous INSERT
3. max(id) FROM ...

In this case, the returned id is the one of asynchronous insertion.

---

<div class="post-metadata">

**Author:** ![rex](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rex/32/59848_2.png) [@rex](https://discourse.nodered.org/u/rex)\
**Post date:** [21 March 2020 20:40 UTC](https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433/4 "2020-03-21T20:40:33Z")

</div>

After some mistakes, I've found my solution [here](https://github.com/node-red/node-red-nodes/issues/583).

Just, I have to find the exact means of all fields, but what I need is on msg.payload.insertID.

 ![Immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba823e39020d4cc2c8f4f5815ebf07cef5c00a6b.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 April 2020 20:40 UTC](https://discourse.nodered.org/t/how-to-retry-id-from-mysql-of-last-insert-into/23433/5 "2020-04-04T20:40:37Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
