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 two tables.

Author  Topic 

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-03-26 : 11:44:57
I have 2 tables

1) Table1

id subid
1 1
1 2
1 3
1 5

2) Table 2
id subid
1 1
3 5
4 6

Tables don't have PK. If records exist in table1 for table 2,I want to exclude.

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-26 : 13:41:56
Not sure what you want. May be this,

select 
*
from
table2 a2
where
not exists ( select
*
from
table1 a1
where a1.id=a2.id
and a1.subid=a2.subid
)
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-29 : 02:38:35
try this too
SELECT
a2.*
FROM
table2 a2
LEFT JOIN
table1 a1 ON a1.id=a2.id
AND a1.subid=a2.subid
WHERE
a1.id IS NULL
Go to Top of Page
   

- Advertisement -