Selecting a data in a table that is not with you in another

Asked

Viewed 50 times

-4

Hello, I’d like to know how you belt a field that you don’t have on another table. logically would be so "selects document code in table x where document code does not exist in table y ";

1 answer

0


whereas the tables are x and y, as mentioned, and that both have the Cpf, for example, the following query returns all existing Cpfs in x that do not exist in y:

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

And the following, all the numbers 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 CPF was used) is you who will have to define, based on one/some of the columns simultaneously existing in the two tables.

  • 1

    I was busy these days but thanks for the tip, it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.