SQLITE – PREPARED statement and in expression

I have a database where users can search for records containing a list of one or more items. I am using IN for searching, but I cannot use IN to process prepared statements. This This is what I tried:

SELECT * FROM tbl1 WHERE col IN (?)

But the prepared statement will pass me the item The list is treated as a single item. How can I do this?

I am using sqlite, if it makes any difference.

you can’t Do this because you can’t bind to an array.

You have to do it in two steps:

>Use one’? ‘Create each value in the SQL array or list.
>Iterate through the array or list and bind each value.

This is true regardless of the database.

You don’t have Explain whether sub-SELECT can be a better solution, but if the value in question is available in another table, maybe it can make it work.

I have a database , The user can search for records containing a list of one or more items. I am using IN to search, but I cannot use IN to process prepared statements. This is what I have tried:

SELECT * FROM tbl1 WHERE col IN (?)

But the prepared statement treats the list of items I pass as a single item. How can I do this?

I am using sqlite, if it makes any difference.

You can’t do this because you can’t bind to an array.

You have to do it in two steps:

>Use one’? ‘Create each value in the SQL array or list.
>Iterate through the array or list and bind each value.

This is true regardless of the database.

You don’t have Explain whether sub-SELECT can be a better solution, but if the value in question is available in another table, maybe it can make it work.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 879 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.