Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Comaore tables

Author  Topic 

engcanada
Starting Member

39 Posts

Posted - 2008-12-03 : 12:24:21
Hi,
How can I compare 2 tables in the same database and retreive data from one of the tabels that does do exist in the other.

Thank you simon

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-03 : 12:39:30
select * from table 1
except
select * from table 2
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 13:33:04
Also another method would be

select *
from
(
select *,1 as cat from table 1
union all
select *,2 from table 2
)t
group by <all fields except cat here>
having sum(case when cat=2 then 1 else 0 end)=0
Go to Top of Page
   

- Advertisement -