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

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-07 : 09:23:06
Shankar writes "I am having two tables A and B. both tables are having their keys as col1,col2. I want to know what will be the query to check the table B is having all rows of Table A."

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2001-12-07 : 09:51:03
This returns the count of rows in A whose keys do not occur in B:

SELECT COUNT(*)
FROM A
LEFT JOIN B ON A.col1 = B.col1 AND A.col2 = B.col2
WHERE B.col1 IS NULL AND B.col2 IS NULL


So this will give 0 if the keys in table B include all those in table A.


Go to Top of Page
   

- Advertisement -