# Using SQL with Node-red

**URL:** <https://discourse.nodered.org/t/using-sql-with-node-red/54029>\
**Category:** General\
**Tags:** database\
**Created:** [20 November 2021 11:42 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029 "2021-11-20T11:42:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyDHill](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@AndyDHill](https://discourse.nodered.org/u/AndyDHill)\
**Post date:** [20 November 2021 11:42 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/1 "2021-11-20T11:42:43Z")

</div>

Have a problem where I need to read the On Change ( new rows) from an SQL table (MS SQL) I have managed to read all records. but as the table grows the response grows.

Problem is I want to read a row in table (last) or all the rows written in last 10 seconds ad send out as an MQTT message. Don't want to send out all lines

Query I am using is

Select \* from Events

I tried to put a where condition and it won't accept even though the query is valid in Microsoft SQL Workbench thing

SELECT \* from Events WHERE EventsID \> 12

Ideally the "12" should be the last record of the last read.

(using the gomake/node-red-contrib-mssql-jb SQL driver)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [20 November 2021 12:55 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/2 "2021-11-20T12:55:13Z")

</div>

add to the sql command

`ORDER BY EventsID DESC`

and

`LIMIT 10`

(for the last 10)

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [20 November 2021 12:55 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/3 "2021-11-20T12:55:52Z")

</div>

Are you using [node-red-contrib-mssql-plus](https://flows.nodered.org/node/node-red-contrib-mssql-plus)?

---

<div class="post-metadata">

**Author:** ![AndyDHill](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@AndyDHill](https://discourse.nodered.org/u/AndyDHill)\
**Post date:** [22 November 2021 09:28 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/4 "2021-11-22T09:28:26Z")

</div>

> [@AndyDHill](#):
>
> gomake/node-red-contrib-mssql-jb

Using - gomake/node-red-contrib-mssql-jb

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [22 November 2021 09:36 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/5 "2021-11-22T09:36:41Z")

</div>

> [@AndyDHill](#):
>
> gomake/node-red-contrib-mssql-jb

Be aware, the `node-red-contrib-mssql-jb` node hasn't been updated in almost 3 years, and it's git repo has now been removed/deleted/hidden.  
It also has zero stars in the node-RED ratings.

I would look for another contrib node that fulfils your needs.

---

<div class="post-metadata">

**Author:** ![AndyDHill](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@AndyDHill](https://discourse.nodered.org/u/AndyDHill)\
**Post date:** [22 November 2021 09:55 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/6 "2021-11-22T09:55:06Z")

</div>

I was starting to think the same seems not to support the WHERE condition

---

<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:** [21 January 2022 09:55 UTC](https://discourse.nodered.org/t/using-sql-with-node-red/54029/7 "2022-01-21T09:55:30Z")

</div>

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