user1342164
user1342164

Reputation: 1454

SQL Get rows from table 1 that dont exist in table 2

I am not really a SQL expert so I was wondering if there is a query that can do this. I have 2 SQL tables, table1 and table2. I need to get an output of rows from table 1 that does not exist in table 2. For example if the data in column 1 row 1 is not in table 2. Is there a way to do this? TIA

I tried the following:

 select dbo.table1.TIN
 From dbo.table1 as T1
 where not exists (select * from dbo.table2 as T2 where T1.TIN = T2.TIN)

Getting error

The multi-part identifier "dbo.table1.TIN" could not be bound.

Upvotes: 0

Views: 53

Answers (2)

shawtydubs
shawtydubs

Reputation: 64

select t1.tin
from table1 tin
where not exists (select 1 from table2 t2 where t1.tin = t2.tin);

Upvotes: 0

SQLChao
SQLChao

Reputation: 7837

I think you just have an issue with the table alias

select T1.TIN
From dbo.table1 as T1
where not exists (select * from dbo.table2 as T2 where T1.TIN = T2.TIN)

Upvotes: 1

Related Questions