0

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);
1
  • You need to give us way more details. What are you selecting? What are you inserting, how are you inserting and why? What does the db-schema look like? What are you actually trying to accomplish? Commented Oct 11, 2016 at 5:31

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.