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
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
)