# Select specific rows from DB using ID list of csv or excel files.

**URL:** <https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709>\
**Category:** KNIME Analytics Platform\
**Created:** [September 30, 2020, 2:41am UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709 "2020-09-30T02:41:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bilgee](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bilgee/32/20053_2.png) [@bilgee](https://forum.knime.com/u/bilgee)\
**Post date:** [September 30, 2020, 2:41am UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709/1 "2020-09-30T02:41:52Z")

</div>

Hello.  
I want to select specific rows from DB. I have a csv file which contains IDs of a several users.  
It looks something like that:  
SELECT \* FROM Table1 WHERE id IN (SELECT id FROM CSVFILE)

Currently I select all rows from a table after that I use the joiner node to get necessary data. How to inject the IDs into select query?  
Is there any efficient method?

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [September 30, 2020, 3:07am UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709/2 "2020-09-30T03:07:17Z")

</div>

@bilgee welcome to the KNIME forum

You should be able to use the DB Merge node

> **[DB Merge](https://hub.knime.com/knime/extensions/org.knime.features.database/latest/org.knime.database.node.io.merge.DBMergeNodeFactory)**
>
> Merges (insert/updates) all data rows from the selected database table that match the values of a row from the selected KNIME input table columns. All selected…

> **[demonstrates the use of DB Update and DB Merge – mlauber71](https://hub.knime.com/mlauber71/spaces/Public/latest/kn_example_db_update_merge)**
>
> demonstrates the use of DB Update and DB Merge

Or if the number of IDs is small you could transform them into a list and feed that as a flow variable into the where statement.

Or you could upload the CSV into a database table and use that.

---

<div class="post-metadata">

**Author:** ![beginner](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/e495f1/32.png) [@beginner](https://forum.knime.com/u/beginner)\
**Post date:** [September 30, 2020, 4:37am UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709/3 "2020-09-30T04:37:58Z")

</div>

The old KNIME database nodes had a Database Looping node. However in the new nodes this was replaced with the Parameterized DB Query reader which has the issue it does 1 query per row (ID in your case) which is slow. You can use [this component](https://hub.knime.com/tobias.koetter/spaces/Public/latest/DB/dbLooping_parameterized) that emulates that functionality (you will probably need to update the component a bit by now).

How does it work? it simply creates a WHERE clause with IN. How many items you can put into IN depends on the database you use.

Albeit your approach with the join is pretty straight forward and if it isn’t slow (because not that much data) I don’t really see the issue with it.

---

<div class="post-metadata">

**Author:** ![bilgee](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bilgee/32/20053_2.png) [@bilgee](https://forum.knime.com/u/bilgee)\
**Post date:** [October 1, 2020, 2:12am UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709/4 "2020-10-01T02:12:01Z")

</div>

Thank you.

Our table is quite large so that we cannot select all data from it. I want to minimize the selection. I will try your solution.

---

<div class="post-metadata">

**Author:** ![bilgee](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bilgee/32/20053_2.png) [@bilgee](https://forum.knime.com/u/bilgee)\
**Post date:** [October 1, 2020, 2:12am UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709/5 "2020-10-01T02:12:19Z")

</div>

Thank you.

I will try your solution.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [April 1, 2021, 2:12pm UTC](https://forum.knime.com/t/select-specific-rows-from-db-using-id-list-of-csv-or-excel-files/27709/6 "2021-04-01T14:12:38Z")

</div>

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