I'm trying to build a set of results from a query in a PHP page. My where clause is complicated and potentially expensive. In my usual languages I'd do something like:
CREATE TEMPORARY TABLE ShortList (ID INT);
INSERT INTO ShortList
SELECT ID FROM Table1 WHERE {Super long query};
SELECT * FROM Table1 JOIN ShortList ON ShortList.ID = Table1.ID;
SELECT * FROM Table2 JOIN ShortList ON ShortList.ID = Table2.Table1ID;
SELECT * FROM Table3 JOIN ShortList ON ShortList.ID = Table3.Table1ID;
SELECT * FROM Table4 JOIN ShortList ON ShortList.ID = Table4.Table1ID;
Then I'd iterate through each resultset pulling each row. Given this data it's not very easy to join across all of the tables; this would result in a lot of duplicate data.
So what's the PHP way to accomplish this?