0

I'm a newbie, just learning SQL and have this question: I have two tables with the same columns. Some registers are in the two tables but others only are in one of the tables. To illustrate, suppose table A = (1,2,3,4), table B=(3,4,5,6), numbers are registers. I need to select all registers in table B if they are not in table A, that is result=(5,6). What query should I use? Maybe a join. Thanks.

2 Answers 2

1

You can either use a NOT IN query like this:

SELECT col from A where col not in (select col from B)

or use an outer join:

select A.col from A LEFT OUTER JOIN B on A.col=B.col where B.col is NULL

The first is easier to understand, but the second is easier to use with more tables in the query.

Sign up to request clarification or add additional context in comments.

Comments

0
Select register from TABLE_B b
Where not exists (Select register from TABLE_A a where a.register = b.register)

I assumed you have a column named register in TABLE_A and TABLE_B

1 Comment

logically i think it works, i will have to try with my tables with 1000+ registers... thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.