Joe Brown
Joe Brown

Reputation: 67

(SQL) How to check if a value is in another table?

I'm not very good with SQL so I apologise.

I want to be able to go through each row on Table A and check if a specific value exists in an entire column in Table B.

I want to see all rows from table A where value is NOT in specific column in table B.

I hope that makes sense.

Upvotes: 0

Views: 236

Answers (2)

GMB
GMB

Reputation: 222392

You can use not exists. Your question is a bit theorical, the but the logic would be:

select a.*
from tablea a
where not exists (select 1 from tableb b where b.col1 = a.col1)

Where values in tabla(col1) should correspond to values in tableb(col1).

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269443

It sounds like not exists:

select a.*
from a
where not exists (select 1 from b where b.col = a.col);

Upvotes: 0

Related Questions