Reference from Specified Twice Table for 'DELETE' in MariaDB
After I implemented the query from that reference into the code, I made an error in yii2
Query :
public function actionDeleteduplicate($date){
Yii::$app->db->createCommand("DELETE t1
FROM HrAttLogsFormatted t1
INNER JOIN
(
SELECT FingerId, MIN(CreatedDate) AS MinCreatedDate
FROM HrAttLogsFormatted
WHERE DateIn = '".$date."' AND Late != ''
GROUP BY FingerId
HAVING COUNT(FingerId) > 1
) t2
ON t1.FingerId = t2.FingerId AND t1.CreatedDate = t2.MinCreatedDate
")->queryAll();
$this->redirect(['index']);
}
Result :
SQLSTATE[HY000]: General error The SQL being executed was: DELETE t1 FROM HrAttLogsFormatted t1 INNER JOIN ( SELECT FingerId, MIN(CreatedDate) AS MinCreatedDate FROM HrAttLogsFormatted WHERE DateIn = '2019-05-03' AND Late != '' GROUP BY FingerId HAVING COUNT(FingerId) > 1 ) t2 ON t1.FingerId = t2.FingerId AND t1.CreatedDate = t2.MinCreatedDate
Does anyone know what is wrong with the code?
execute()
instead ofqueryAll()
for delete queries. – rob006DELETE
function not onlySELECT
where the function is executed byexecute()
– Aldan