I have a table, Foo. I run a query on Foo to get identifiers from a subset of Foo. Then I want to run a more complex set of queries, but only by these identifiers. Is there an effective way to do this? The best I can think of is to create a query, for example:
SELECT ...
WHERE ...
AND id IN (1, 2, 3, 9, 413, 4324, ..., 939393)
That is, I am creating a huge sentence "IN". Is it effective? Is there a more efficient way to do this, or is it the only way to join an internal query that receives identifiers? If this helps, I use SQLObject to connect to the PostgreSQL database, and I have access to the cursor that executed the query to get all IDs.
UPDATE: I have to mention that more complex queries either rely on these identifiers or create more identifiers to search in other queries. If I made one big query, I would end up joining six tables at the same time or in a way that might be too slow.
source
share