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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Comparing 2 or more fields at the same time...

Author  Topic 

Andraax
Aged Yak Warrior

790 Posts

Posted - 2001-08-09 : 05:47:54
Hi!

Let's say I have 2 tables, looking like this:

table1:
id1 id2
1 1
1 2
1 3
2 1
table2:
id1 id2
1 1
1 2
1 3
2 1
2 2

What I want to do is to compare the tables and fetch rows from table2 which doesn't exist in table1. How can I compare both the fields at the same time? The only way I have come up with is this:

select * from table2
where convert(varchar, id1)+convert(varchar, id2) not in (select convert(varchar, id1)+convert(varchar, id2) from table1)

Is there a better way to do it?

   

- Advertisement -