# How to compare two msg.payload in a same flow

**URL:** https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174
**Category:** General
**Created:** [6 May 2020 14:16 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174 "2020-05-06T14:16:28Z")
**Posts on this page:** 7
**Page:** 2

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 May 2020 09:55 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/21 "2020-05-09T09:55:49Z")

</div>

Yes. What does your payload look like before the SQL node. Add a debug before SQL node and after. Show me the output expanded. Also, your trim doesn't work. Copy & paste the code from the trim function here

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 May 2020 09:59 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/22 "2020-05-09T09:59:41Z")

</div>

Also, I didn't realise this was mariaDb

Remove TOP 1 from the SQL then add LIMIT 1 at the end

E.g...

```auto
var spokenAsText = msg.payload.trim();// or where ever the speech to text is
var SQL = "SELECT * FROM USER WHERE VOICE = '" + spokenAsText + "' LIMIT 1";
msg.topic = SQL; 
return msg;

```

---

<div class="post-metadata">

### Author: ![lingzhongli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lingzhongli/32/20078_2.png) [@lingzhongli](https://discourse.nodered.org/u/lingzhongli)
#### Post date: [9 May 2020 10:08 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/23 "2020-05-09T10:08:52Z")

</div>

`trim()` function node

```auto
var spokenAsText = msg.payload.trim();// or where ever the speech to text is
var SQL = "SELECT * FROM USER WHERE VOICE = '" + spokenAsText + "' LIMIT 1";
msg.topic = SQL; 
return msg;

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/550549e94431ddbffb03a524cdc24402eb98130a.png)

so this mean successful?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 May 2020 10:09 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/24 "2020-05-09T10:09:50Z")

</div>

Yes. It found 1 matching row.

Ps, delete the JSON node at the end. Not necessary.

---

<div class="post-metadata">

### Author: ![lingzhongli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lingzhongli/32/20078_2.png) [@lingzhongli](https://discourse.nodered.org/u/lingzhongli)
#### Post date: [9 May 2020 10:18 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/25 "2020-05-09T10:18:43Z")

</div>

if i also want check the `verify` data...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/ddf84e20e48e58235b1728d3e14f07e0dbfc5747.png)

E.g  
if `verify` = `1` , it will show data...

that mean i want voice and verify data match...  
if one of the voice or verify no match...it also no show data..

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 May 2020 10:22 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/26 "2020-05-09T10:22:47Z")

</div>

I don't understand your question but if you mean ONLY GET DATA IF VERIFY == 1 then do this...

```auto
var spokenAsText = msg.payload.trim();// or where ever the speech to text is
var SQL = "SELECT * FROM USER WHERE VOICE = '" + spokenAsText + "' AND VERIFY = 1 LIMIT 1";
msg.topic = SQL; 
return msg;

```

Ps, these questions are about basic SQL syntax - not node-red. You should ask database questions on the mysql or MariaDb forums.

---

<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: [8 July 2020 10:22 UTC](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174/27 "2020-07-08T10:22:57Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/how-to-compare-two-msg-payload-in-a-same-flow/26174.md?page=1)
