___ ___ erkimt Compare id two tables and insert value when id does not exist ______ qstntxt ___
Hello, I'm comparing two tables that have the same data, %code% and %code% , the %code% 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 %code% .

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%     
______ azszpr344062 ___

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

    
___

0
Hello, I'm comparing two tables that have the same data, 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);
    }
    
asked by anonymous 17.11.2018 / 19:23

1 answer

0

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

    
17.11.2018 / 21:03