For each new row in Mysql trigger

Hi, I would like to use n8n to trigger a sequence whenever something occurs in my app / database.
For example, the most basic scenario is when a new users signs up for an account - this results in a new row inside the Users table.

What is the recommended way to store a variable, such as user ID somewhere in n8n?
I’m thinking this way I could:

  1. Get data from Mysql every X amount of time (trigger: interval + node: mysql)
  2. Then check which IDs are bigger than the one I have stored
  3. Do something with those IDs (let’s say send them an email)
  4. Update the state in the variable to remember for the next run, which IDs were processed.

The workflow would probably look something like the screenshot below, but I’m missing the piece that would allow me to know what IDs were processed already.

Thanks for any tips on the matter!

n8n version 0.188.0
running on Docker

Hi @Matija_Kovac, you could consider using n8n’s static workflow data to store which row you have last processed. This would require a bit of code though (check out the docs for details) and most importantly does not work when manually running/testing your workflow.

So perhaps you might want to consider adding an additional column (something such as processed_by_n8n) instead and simply update it whenever you’re processed an item (and then use it in your query, of course)?

1 Like

Hi Tom,
thanks for getting back to me, both options look interesting - I’ll look into this and see what works best for my use case.

1 Like