Reputation: 11
i have a total of 6 different tables that i select from then insert to a table before i do another select i was wondering if there was a way to skip the insert part and just do a select and combine all table data. the problem with the select and insert then select aproach is it gets really slow when there are about 1k+ records inserted. it takes about 30sec to 1min or more
im trying something like this
$sql = "select 1";
$statement = $conn->query($sql);
$rowset = $statement->fetchAll();
$sql1 = "select 2";
$statement1 = $conn->query($sql1);
$rowset1 = $statement1->fetchAll();
$combine = array_merge($rowset,$rowset1);
foreach ($combine as $key => $part) {
$sort[$key] = strtotime($part['date']);
}
array_multisort($sort, SORT_DESC, $combine);
Upvotes: 0
Views: 42
Reputation: 34284
To me it seems that you are replicating in php what you could do in sql. The above code in sql looks sg like this:
(select 1)
union all
(select 2)
order by date desc
You may have to tweak the order by clause depending on what data you exactly have in the date field. Otherwise, the above sql code should produce the exactly same results as your php code.
Upvotes: 3