Reputation: 1007
Say I have an array with IDs:
values = [0, 43, 5]
Now I want to go through my table "tbl_EVENTS" and return every row where EVENTID = 0, 43, or 5.
Every ID will only appear once. So I could technically do three different queries.
I am working with a javascript
frameworks that builds an SQL string in the end, so I could wrap this into a for loop if necessary.
Upvotes: 0
Views: 34
Reputation: 1320
This what you are looking for:
If your values = [0, 43, 5]
an array then, we can use join method with template literals.
const values = [0, 43, 5];
`SELECT * FROM tbl_EVENTS WHERE EVENTID IN(${values.join(',')})`
Upvotes: 2