question

tlredd68 avatar image
tlredd68 asked

Counts Query

I have 3 tables: Table 1, Table 2 and Table 3. Count of how many times there is a match in Table 1 to Table 3. Count of how many times there is a match in Table 2 to Table 3. Count of how many times there is a match in Table 1 to Table 2. Count of how many times there is a match in all 3 tables (Table1, Table2 and Table3). I do have a unique key. There are dupes in the tables so I would need a distinct count and total count. Right now, I have it broken up into single select queries but was wondering if this is a way to combine it all and run 1 script. Thx
sql-server-2005count
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks, Kev! This worked like a charm.
0 Likes 0 ·

1 Answer

· Write an Answer
Kev Riley avatar image
Kev Riley answered
If you have them already, simply `union` the result sets together, possibly with a descriptive column to distinguish each one..... select 'desc1' as countType, count_query1 union all select 'desc2', count_query2 union all . . .
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.