Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need query help

Status
Not open for further replies.

pandatime

Programmer
Jan 29, 2010
92
AU
Hi,

I have situation where I need to check if rows do not exist across tables. The problem is, the columns I am checking to determine this contain data that is not unique across the tables.

For example, myTable1 contains:

pk id system_date
1 10 2010-01-01
1 10 2010-01-02
2 10 2010-01-03
2 10 2010-01-04

and myTable2 contains:

pk id system_date
1 10 2010-01-01
1 10 2010-01-02
2 10 2010-01-03
2 10 2010-01-04

The problem arises in my code below. Because there are multiple matches here that if not perfectly matched to one another, the check fails. That is, SQL Server isn't matching the matching rows together. It appears to just be comparing rows randomly, so of course many of them won't match to each other, even though all the rows DO match (as in my example above).

How can I code for this?

Thanks much

Code:
select * from myTable1 s
where not exists
(
  select * from myTable2 r
  where s.pk = r.pk
  and s.id = r.id
  and s.system_date = r.system_date
)
 
Actually, this is another "nevermind" - I was looking at the wrong results - doh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top