mySQL, update 2 cells

Hello everybody!
I know how to update a cell with the mySQL node:

msg.topic = "UPDATE Tabelle1 SET Column1 = '" + msg.payload.value1+ "' WHERE Zeilen_ID = " + "'" + msg.payload.ID+ "'";;
    
return msg;

But how can I update two cells at the same time?
Column1 = value1
Column2 = value2

I tried the following, but unfortunately it doesn't work:

msg.topic = "UPDATE Tabelle1 SET (Column1, Column2) " +
    "VALUES ( " + msg.payload.value1 + ", " + msg.payload.value2 + ")"
    WHERE Zeilen_ID = " + "'" + msg.payload.ID + "'";;
  
return msg;

Can anyone help here?

I think you should be aiming at
UPDATE table SET column1 = value1, column2 = value2 WHERE column3 = id

However it is not good practise to include the values in msg.topic, better to use prepared queries like this

msg.topic = "UPDATE mytable SET temperature = ?, humidity = ?, location = ? WHERE id = 100"
msg.payload = [17, 85, "door"]   // An array of values to substitute for ? marks in msg.topic
1 Like

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