Selecting a data in a table that is not with you in another [closed]

-4

Hello, I'd like to know how to draw a field that I do not have on another table. logically would be like this "selects code of the document in table x where the code of the document does not exist in table and";

    
asked by anonymous 13.08.2017 / 16:05

1 answer

0

Since the tables are x and y , as mentioned, both have the cpf field, for example, the following query returns all existing CPFs in x that do not exist in and :

SELECT
    cpf
FROM
    x
WHERE
    cpf NOT IN (SELECT cpf FROM y)

And the following are all the CPFs that exist in y but not in x :

SELECT
    cpf
FROM
    y
WHERE
    cpf NOT IN (SELECT cpf FROM x)

The comparison criterion (s) (here was used CPF) you will have to define, based on one / some of the columns simultaneously existing in the two tables.

    
14.08.2017 / 13:14