I am trying to use dynamically created list in WHERE, for example:
select * from books where id in (123, 120, 125) and bookCover = 'Hardcover'
I want to use it with rawQuery and I have prepared SQL in “?” form, for example:
select * from books here id in (?) and bookCover = ?
is there any way, how to put a list of “ids” in the IN clause of the select? or do I have to forget about prepared statements with “?” ?
Thanks in advance for any help. Searched
No – I do NOT know ANY DB (like Oracle, SQL Server, SQLite, Postgres etc.) which provides for what you ask…
The nearest solution you can get is to insert the IDs into a second table and then use a subquery in the
INpart…MyIDTablehat 2 fieldsQNO(is just a key) andID(contains the IDs you want in yourIN… you first insert 3 rows with the same QNO and the respective IDs…Then you can do a
SELECTlike this:Which basically allows for this:
After you are done looking for that specific set of IDs you can clean up by
DELETE FROM MyIDTable WHERE QNO = 3.