# How to Prevent Insertion of Duplicate Data to the Database with Node-Red Function Node?

**URL:** https://discourse.nodered.org/t/how-to-prevent-insertion-of-duplicate-data-to-the-database-with-node-red-function-node/1660
**Category:** Dashboard
**Created:** [18 July 2018 09:34 UTC](https://discourse.nodered.org/t/how-to-prevent-insertion-of-duplicate-data-to-the-database-with-node-red-function-node/1660 "2018-07-18T09:34:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)
#### Post date: [18 July 2018 09:34 UTC](https://discourse.nodered.org/t/how-to-prevent-insertion-of-duplicate-data-to-the-database-with-node-red-function-node/1660/1 "2018-07-18T09:34:21Z")

</div>

Hi,

I need an help here. I have two text inputs, one drop down and a button on my dashboard ui. I would like to check whether the data from the inputs already available on the database table. If yes, I want to prevent the users from inserting the data. If no, then only I want to allow the users to insert the data successfully.

For example, if the user information already available on the database, then the user unable to enter the same user information again.

I would like to do this by adding a function node with two msg.topic for SELECT and INSERT MySQL command. Is that possible? If yes, how to do it? How to distinguish both msg.topic and return them?

I understand that data duplication prevention can be done on the database itself. If that is the only way, how to return a result that the data already available and the user unable to add the information on dashboard ui?

Hope to hear from you soon. Thanks for helping.

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [18 July 2018 09:49 UTC](https://discourse.nodered.org/t/how-to-prevent-insertion-of-duplicate-data-to-the-database-with-node-red-function-node/1660/2 "2018-07-18T09:49:46Z")

</div>

> [@rishanaziz](#):
>
> I understand that data duplication prevention can be done on the database itself.

Have a look here:

> **[SQL EXISTS Operator](https://www.w3schools.com/sql/sql_exists.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

This is not the only way to do what you want, I'm sure more suggestions will come.

---

<div class="post-metadata">

### Author: ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)
#### Post date: [25 July 2018 02:02 UTC](https://discourse.nodered.org/t/how-to-prevent-insertion-of-duplicate-data-to-the-database-with-node-red-function-node/1660/3 "2018-07-25T02:02:48Z")

</div>

Hi Garry,

Thank you for the suggestion. I'm using MySQL COUNT() Function and get the number of data available. Then I compare with 0 using switch node. It works for me for the moment.
