Let’s suppose I have seven tables, and I want to perform the same query on all of them, and then return the result. Right now I have some code like this
$dates = array();
foreach ($tables as $table) {
$result = runStatement("
SELECT MIN(StartDate) as Start,
MAX(EndDate) as End
FROM $table WHERE ProjectID = ?",
array($id));
$stageDates[$table] = $result[0];
}
echo json_encode($dates);
It works, but it is prohibitively slow because it has to initiate and retrieve results from seven different queries. Is there a way to amalgamate all of the queries into one? Is there any other way to speed it up?
Using join with subquery will solve the problem