Click here to Skip to main content
15,446,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to have a select query which compares 2 tables of different both local databases and return the values of one table where they are not exists in second table, tried this but there are errors
SQL
declare library.dbo.phones as t1
 
 select * from [library].dbo.table_1 as t2 where t2.onoma Not like  t1.name

or this
SQL
declare library.dbo.phones as t1
 
 select * from [library].dbo.table_1 as t2 where t2.onoma Not in  t1.name
Posted

Use Not Exists[^]
An example:
SQL
select * from [databasename].dbo.table1 t1 where
not exists
(
select * from [databasename].dbo.table2 t2 where t1.name = t2.onoma
)
 
Share this answer
 
v2
Comments
Member 3892343 11-Jun-15 2:51am    
thank you.
Yeah, you can use Not in

SQL
select * From [databasename].dbo.table1 where Column not in(select column from [databasename].dbo.table2 )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900