consult 2 tables to see which records are not in the first table

1

I have 2 tables of people from 1 system which has 2 versions, each version with a different database, what I want to know is that people from the tabla t_evaluacion_vulnerabilidad are not in the table t_evaluacion_dean , here I share them the code to consult

select cedula from personas1.t_persona_vulnerabilidad where cedula not in (select cedula from personas1.t_persona_dean)

Running it like this does not bring me any results.

    
asked by Angel Gutierrez 24.04.2018 в 15:02
source

3 answers

1

I think it would be convenient to use NOT EXISTS, if you want to get the records that are not in another table;

SELECT cedula 
  FROM personas1.t_persona_vulnerabilidad t1
 WHERE NOT EXISTS (SELECT NULL
                     FROM personas1.t_persona_dean t2
                    WHERE t2.cedula= t1.cedula)
    
answered by 24.04.2018 / 15:46
source
0

Greetings I think that you have your query well, now in your questions you say that the tables are in different databases and I do not see that you make references to the database for example. See if this works for you.

select cedula from db1.personas1.t_persona_vulnerabilidad where cedula not in (select cedula from db2.personas1.t_persona_dean)
    
answered by 24.04.2018 в 16:34
0

Hello!

I find inconsistency between your problem and your example . You name the table " t_evaluacion_vulnerabilidad " and " t_evaluacion_dean " in your proposal and then make reference to the tables " personas1.t_persona_vulnerabilidad " and "< em> personas1.t_persona_dean ".

I raise : I see that your SQL query is well written and apparently ... is consistent. Therefore, it means that all the people stored in your table t_evaluacion_dean , are in turn stored in t_evaluacion_vulnerabilidad .

Conclusion : There is no person in Table No. 1 (t_evaluacion_dean) that is NOT in Table No. 2 (t_evaluacion_vulnerabilidad).

    
answered by 24.04.2018 в 16:58