I have a table with a list of IDs. I use a query to select that and then fetch it as an array (I know how to do this). Then I want to select rows from another table where the IDs are in the array fetched earlier.
How would I do this? Thanks in advance.
You’d most likely want to do a
WHERE field IN (...)type query. It’s essentially the equivalent ofWHERE field=X or field=Y or field=Z or ...for every value listed in theINclause.Given that you’ve got an array of IDs already, the simplest way is to build the query like this:
The usual provisos apply – be careful about SQL injection holes, always check query results for failure, etc…