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
 New to SQL Server Programming
 how to compare 2 tables

Author  Topic 

josephdickhoener
Starting Member

1 Post

Posted - 2007-12-17 : 17:02:58
need to know how to check both table data and return only data that doesn't match the other table data


select distinct dept_name
from bb_guide_party_dept d, binbox_dept e where d.dept_id = e.dept_id
and e.active_Flag = 1

union
select distinct dept_name
from bb_guide_party_dept a, binbox_dept b where a.dept_id = b.dept_id
and e.dept_name not the same as b.dept_name

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-17 : 17:09:47
[code]select e.dept_name
from bb_guide_party_dept as d
inner join binbox_dept as e on e.dept_id = d.dept_id
and e.active_Flag = 1

union

select b.dept_name
from bb_guide_party_dept as a
inner join binbox_dept as b on b.dept_id = a.dept_id [/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-17 : 17:11:52
Using SQL Server 2005?
select	e.dept_name
from (
select e.dept_name,
ROW_NUMBER() OVER (PARTITION BY e.dept_name ORDER BY e.active_Flag DESC) AS RecID
from bb_guide_party_dept as d
inner join binbox_dept as e on e.dept_id = d.dept_id
) as d
where RecID = 1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-12-18 : 06:21:29
third party tool is there for this

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page
   

- Advertisement -