I'll try to explain this way:
%pre%Code that I already have, it already performs the comparison but does not include the status of "deleted":
%pre%I'll try to explain this way:
%pre%Code that I already have, it already performs the comparison but does not include the status of "deleted":
%pre%Hello, you can run the query below to find out who was excluded:
%pre%And to update the status you can execute only the command below:
%pre%See the examples here link
tabela1
and tabela2
, the tabela2
will have data deleted over time, so I need to identify the field that was deleted and insert a " exclusion status "in a column of tabela1
.
I'll try to explain this way:
+---------+---------+----------+
| TABELA2 | TABELA1 | |
+---------+---------+----------+
| cod1 | cod1 | |
+---------+---------+----------+
| | cod2 | EXCLUIDO |
+---------+---------+----------+
| cod3 | cod3 | |
+---------+---------+----------+
| | cod4 | EXCLUIDO |
+---------+---------+----------+
Code that I already have, it already performs the comparison but does not include the status of "deleted":
$teste1 = "SELECT * FROM tabela2 as a INNER JOIN tabela1 as c ON (a.cod2=c.cod1)";
$teste2 = mysqli_query ($db,$teste1);
while($teste3 = mysqli_fetch_array($teste2)){
$teste = $teste3["0"];
$insert = "UPDATE tabela1 SET campo = 'Entregue' WHERE cod1 NOT IN ($teste)";
mysqli_query ($db,$insert);
}
Hello, you can run the query below to find out who was excluded:
select * from tabela1 t1 where not exists(select * from tabela2 t2 where t2.id = t1.id )
And to update the status you can execute only the command below:
update tabela1 t1 set t1.status = "EXCLUIDO" where not exists(select * from tabela2 t2 where t2.id = t1.id )
See the examples here link