# Select data from SQlite not working

**URL:** <https://discourse.nodered.org/t/select-data-from-sqlite-not-working/57236>\
**Category:** General\
**Created:** [26 January 2022 05:30 UTC](https://discourse.nodered.org/t/select-data-from-sqlite-not-working/57236 "2022-01-26T05:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TROJAN053](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@TROJAN053](https://discourse.nodered.org/u/TROJAN053)\
**Post date:** [26 January 2022 05:30 UTC](https://discourse.nodered.org/t/select-data-from-sqlite-not-working/57236/1 "2022-01-26T05:30:56Z")

</div>

Hi,  
I am querying from sqlite using but data is not getting selected and under debug its shows undefined.  
My flow is here

```auto
[{"id":"261492c80ec624f0","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"8459c16cfddf3fab","type":"inject","z":"261492c80ec624f0","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":260,"wires":[["de17100763398a0a"]]},{"id":"de17100763398a0a","type":"function","z":"261492c80ec624f0","name":"","func":"var msg = {\n \"topic\" : \"SELECT seq from sqlite_sequence Where name = 'Stn_loss_L3_VIN'\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":220,"wires":[["db8ee5ccff734a80"]]},{"id":"db8ee5ccff734a80","type":"sqlite","z":"261492c80ec624f0","mydb":"53148151.a90cc","sqlquery":"msg.topic","sql":"","name":"C","x":425,"y":220,"wires":[["3d852928ed498b16"]],"l":false},{"id":"3d852928ed498b16","type":"function","z":"261492c80ec624f0","name":"","func":"var msg = {\n \"topic\" : \"SELECT Station from Stn_loss_L3_VIN Where Master_ID =\"+ \"'\" + msg.payload[0].seq + \"'\"\n}\n//var a = flow.get('id');\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":220,"wires":[["74dcedd03dc65a66"]]},{"id":"f71dd4f3b43c60de","type":"sqlite","z":"261492c80ec624f0","mydb":"53148151.a90cc","sqlquery":"msg.topic","sql":"","name":"C","x":705,"y":220,"wires":[[]],"l":false},{"id":"74dcedd03dc65a66","type":"debug","z":"261492c80ec624f0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":220,"wires":[]},{"id":"53148151.a90cc","type":"sqlitedb","db":"C:\\Users\\PASYSTEM\\Andon.db","mode":"RWC"}]

```

![Error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ed9c13a23ca281752f933ed8d94ee4a42e37756.jpeg)  
 ![Stn_db](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/29674dbb69bdf90f812130e1b1ad71e3eb3500c4.jpeg)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 January 2022 06:10 UTC](https://discourse.nodered.org/t/select-data-from-sqlite-not-working/57236/2 "2022-01-26T06:10:24Z")

</div>

The `Master_ID` is defined as an integer, the select statement is trying to match with a string = no match.

You can change the 2nd function node to something like:

```auto
let msg = {}
msg.topic = `SELECT Station from Stn_loss_L3_VIN Where Master_ID = ${msg.payload[0].seq}`
return msg

```

Then again, you could do both these queries in a single statement with a subselect, subquery or join, eg something like:

```auto
SELECT t1.seq, t2.Station FROM sqlite_sequence t1
INNER JOIN Stn_loss_L3_VIN t2 
ON t1.seq = t2.Master_ID

```

---

<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:** [27 March 2022 06:11 UTC](https://discourse.nodered.org/t/select-data-from-sqlite-not-working/57236/3 "2022-03-27T06:11:21Z")

</div>

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