x

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

more ▼

asked Mar 09, 2011 at 10:57 AM in Default

avatar image

tlredd68
111 7 8 10

Thanks, Kev! This worked like a charm.

Mar 09, 2011 at 11:23 AM tlredd68
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

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    
 .
 .
 .
more ▼

answered Mar 09, 2011 at 11:01 AM

avatar image

Kev Riley ♦♦
66.8k 48 65 81

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2036
x53

asked: Mar 09, 2011 at 10:57 AM

Seen: 777 times

Last Updated: Mar 09, 2011 at 10:58 AM

Copyright 2018 Redgate Software. Privacy Policy