'how to delete duplicate data table in SQL with PHP
I am trying to delete duplicate data from a table, but keeping the 1º record tha was made, the first id of this data. But i need to delete using specific period parameters which i already know contains duplicates, the duplicate data are from 12th of this month.
Here's PHP code that i'm using:
require("../conn/conn.php");
require("../conn/conn-relatorio.php");
require("../funcoes/funcoes.php");
$URL = $_SERVER['SERVER_NAME'];
$query = "DELETE FROM tb_relatorio08_cdsdetalhado WHERE
cd_codigo NOT IN (SELECT MIN(cd_codigo) AS 'ID' FROM tb_relatorio08_cdsdetalhado GROUP BY cd_supervisor, nu_at, nu_tipoServico)
and DAY(dt_cadastro) = 12 AND MONTH(dt_cadastro) = 1 AND YEAR(dt_cadastro) = 2022";
$result = $connRelatorio->query($query);
if ($result->error) {
echo "Error: " . $result->error;
}else{
echo "sucesso.";
}
?>
Doing the direct query in SQL it counts error 1093, saying thata i cannot specifiy the table for update in from, but i am not doing an update.
Where am i going wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
