0

Is it possible to compare the count of 2 separate queries in one step?

I have table A which has x records. From table B, I want to check that all x records are within it.

I'm struggling to find a way to go this. I've been looking at this for days and the closest I've got is returning only if the exact records are in A and B, no difference or subset.

pm13
  • 735
  • 7
  • 23
  • 36
  • is there expected to be a 1:1 mapping between A and B? – gbn Oct 14 '11 at 13:05
  • No, there can be a 1:0 or partial 1:1 match. As part of a subquery I need to find out if it's true if all of A are in B – pm13 Oct 14 '11 at 13:19

1 Answers1

0
SELECT
   COUNT(*) AS CountA,
   COUNT(B.key) AS CountB,
   COUNT(*) - COUNT(B.key) AS DifferenceCount
FROM
   tableA A
   LEFT JOIN
   tableB B ON A.key = B.key

The JOIN can have an many columns as need to determine the match

gbn
  • 422,506
  • 82
  • 585
  • 676