# How to calculate 2 msg.id coming from 2 pub different topics simulataneously

**URL:** https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730
**Category:** General
**Created:** [11 September 2020 07:16 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730 "2020-09-11T07:16:13Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 07:16 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/1 "2020-09-11T07:16:13Z")

</div>

Sir,Good morning  
I want to check 2 msg.id is simultaneously coming from 2 different pub topics and then i want to catch CR\_SUCCESS from one Sub topic if both that msg.id is present in my database.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [11 September 2020 07:33 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/2 "2020-09-11T07:33:31Z")

</div>

Hi @shipra

before you can compare the two values you'll need to get them into a single message.

There is a recipe for joining separate streams of messages together in the cookbook - [https://cookbook.nodered.org/basic/join-streams](https://cookbook.nodered.org/basic/join-streams)

That recipe shows how to join separate messages together, but it does assume the value you want to combine is in `msg.payload`. So you may need to use a Change node to move the value of `msg.id` to `msg.payload` before passing to the Join node.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 08:04 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/3 "2020-09-11T08:04:13Z")

</div>

Sir, Actually i am taking 2 input from user  
1:Person ID )FOB MQTT node  
2:Trade ID )TRADE MQTT node  
Scenario  
I am taking both person id as well as trade id from that person,i want to check both inout from database simultaneously ,if both are present then only print CR\_SUCCESS in MATCH(Sub node MQTT)  
how to do this?

Things already done successfully in node red  
FOB node done with DB  
TRADE Node done with DB  
Now stucking with case 3 i.e checking both FOB and TRADE together with DB

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 September 2020 08:13 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/4 "2020-09-11T08:13:32Z")

</div>

That sounds like a SQL thing rather than Node-RED.

Maybe something like:

```sql
SELECT * FROM mytable WHERE person_id <> "" AND trade_id <> "";

```

?

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 08:18 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/5 "2020-09-11T08:18:27Z")

</div>

```auto
Ok ,Sir one query is there that Both MQTT pub Nodes is storing value in msg.payload so in sql how can i write person is<>"msg.payload" cand trade_id<>" msg.payload"
both msg.payload then takes 1 value only 

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [11 September 2020 08:24 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/6 "2020-09-11T08:24:47Z")

</div>

I think we may be missing a load of information.

You are "taking the values from the user" - how are you doing this? Is it a single form? Are you collecting both values from the form at the same time? Or are you using separate inputs?

Also, if you are taking values from the user, why send them to MQTT only to have to use them in Node-RED again?

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 08:32 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/7 "2020-09-11T08:32:42Z")

</div>

> [@shipra](#):
>
> ```auto
> 
> ```

For 3rd case that is ,for checking both FOB ID as well as TAD ID from DB,in my gateway code after taking both inputs from user ,i am publishing those values in their respective mqtt pub nodes .  
So now i have to check for my 3rd Case ,if both ID's are present in DB then Print CR\_SUCCESS in SUB node (MATCH NODE).

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 08:53 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/8 "2020-09-11T08:53:05Z")

</div>

```auto
var w1=msg.payload
if(w1.length==8)
{
    var payload1=w1;
}
if(w1.length==4)
{
  var payload2=w1;
}

let newMsg1 = {};
newMsg1.topic =`SELECT * FROM NCS_DATABASE3 WHERE FOB_TAG_ID ='${payload1}' AND TRADE_ID='${payload2}'`;
return newMsg1;

 

```

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 09:03 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/9 "2020-09-11T09:03:38Z")

</div>

![i](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e6579707371221b0fbb1c67b5ad200d683751702.png)

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

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [11 September 2020 13:33 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/10 "2020-09-11T13:33:48Z")

</div>

please tell the procedure.

---

<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: [10 November 2020 13:33 UTC](https://discourse.nodered.org/t/how-to-calculate-2-msg-id-coming-from-2-pub-different-topics-simulataneously/32730/11 "2020-11-10T13:33:51Z")

</div>

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