# Two different SQLite3 Databases in one flow

**URL:** <https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601>\
**Category:** General\
**Created:** [25 February 2021 07:03 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601 "2021-02-25T07:03:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![iotred3307](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotred3307/32/35716_2.png) [@iotred3307](https://discourse.nodered.org/u/iotred3307)\
**Post date:** [25 February 2021 07:03 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/1 "2021-02-25T07:03:20Z")

</div>

Hello NodeRed Team,

I have two different sqlite3 databases in one flow. I want to select one value, each from those different databases, and compare. Unfortunately, when I change the path in one database, the other automatically gets changed as per the modified one.

How can I resolve this issue?

---

<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:** [25 February 2021 07:40 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/2 "2021-02-25T07:40:57Z")

</div>

Instead of editing the config - add a 2nd config.

Example...  
 ![N1TUMn4PSy](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e99a366f4839b69990caa3d91e28e8adf95d279.gif)

---

<div class="post-metadata">

**Author:** ![iotred3307](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotred3307/32/35716_2.png) [@iotred3307](https://discourse.nodered.org/u/iotred3307)\
**Post date:** [25 February 2021 08:46 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/3 "2021-02-25T08:46:16Z")

</div>

Thank you very much. Now that I could pass select queries, how I can compare both the outputs and create an output that I can write to a S7 data block? I am using JOIN but cannot find a solution for that.

 ![S7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27d05fb1614c9351f6157a0d165117798388cbb6.png)

---

<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:** [25 February 2021 08:50 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/4 "2021-02-25T08:50:12Z")

</div>

what comes out of the join? (add a debug)

tip, use a function node & [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) statements to compare the 2 values

See also [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions)

---

<div class="post-metadata">

**Author:** ![iotred3307](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotred3307/32/35716_2.png) [@iotred3307](https://discourse.nodered.org/u/iotred3307)\
**Post date:** [25 February 2021 08:57 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/5 "2021-02-25T08:57:31Z")

</div>

The output of both the databases are attached in the snapshot. I am trying to join them manually to create an Array. Doesn't work. I think I am doing some mistake.

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4af289499282635542183189b1e3361aff46b334.png) ![S7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/8209c257cef84fc9fa9a146ef728d647fb1e0704.png)

---

<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:** [25 February 2021 09:02 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/6 "2021-02-25T09:02:44Z")

</div>

I dont see any output from your join (you didnt set the count).

A better solution...

1. add a change node AFTER the TOP orange DB node & set msg.topic to "data1"
2. add a change node AFTER the BOTTOM orange DB node & set msg.topic to "data2"
3. Change the join node to create "key/val object" and enter `2` in the count  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf95156e3d2d05c095161c2eaf10911f31d09083.png)

THEN operate the 2 querys and you should see something usable come out of the join node

---

<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:** [25 February 2021 09:13 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/7 "2021-02-25T09:13:35Z")

</div>

Rather than using a Join node (which will work if you configure it correctly), connect them in series. Feed an inject node into the first db, then feed the result into a Change node which Moves `msg.payload` into a message property, `msg.db1Results` for example. Then feed that into the second db node . The output will then contain the second results in msg.payload and the original results should still be in `msg.db1Results`.

---

<div class="post-metadata">

**Author:** ![iotred3307](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotred3307/32/35716_2.png) [@iotred3307](https://discourse.nodered.org/u/iotred3307)\
**Post date:** [25 February 2021 10:08 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/8 "2021-02-25T10:08:08Z")

</div>

Thank so.

Sorry for asking you this basic question again. After joining data 1 and data 2, I got this. How can I put the values in the compare function?

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/41867595065b683b694a4c1c0eb84f717b95278c.png)

---

<div class="post-metadata">

**Author:** ![iotred3307](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotred3307/32/35716_2.png) [@iotred3307](https://discourse.nodered.org/u/iotred3307)\
**Post date:** [25 February 2021 10:09 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/9 "2021-02-25T10:09:02Z")

</div>

Thank you. Will try this one. 🙂

---

<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:** [25 February 2021 10:17 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/10 "2021-02-25T10:17:26Z")

</div>

I am afraid you really need to do some learning.

* * *

> [@iotred3307](#):
>
> How can I put the values in the compare function?

If you read the link i posted...

> [@Steve-Mcl](#):
>
> tip, use a function node & [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) statements to compare the 2 values

you would see your error (clue - missing parenthesis)

Additionally, where do you think `object.data1` comes from? Read this to learn how to use the debug panel to find the right path to any data item: [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)

  
  

#### Recommended Learning...

I also recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

  

Then do some basic online JavaScript training.

---

<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:** [26 April 2021 10:18 UTC](https://discourse.nodered.org/t/two-different-sqlite3-databases-in-one-flow/41601/11 "2021-04-26T10:18:15Z")

</div>

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