I am trying to copy data from one database table to another. Below is the MySQL syntax I am working with:
$array = [];
$q1 = DB::inst()->select( "stu_term" );
foreach($q1 as $r1) {
$array[] = $r1;
}
$bind = [ ":stuID" => $r1['stuID'],"termID" => $r1['termID'],":level" => $r1['level'] ];
$q3 = DB::inst()->query(
"INSERT INTO stu_term (stuID,termID,termCredits,level)
SELECT stuID,termID,SUM(attCred),level
FROM stu_acad_cred
WHERE stuID <> :stuID AND termID <> :termID AND level <> :level
GROUP BY stuID,termID,level)",
$bind);
I am trying to avoid duplicate entries ergo my multiple 'AND' conditions and the 'GROUP BY' clause. The issue I am having is that only one row from the stu_acad_cred table is being inserted into the stu_term table. Any help with seeing why my current SQL code isn't working is greatly appreciated.