Hi,
I am having problems getting the right count(*) when I join two tables. See code below:
What I get for count(*) is the "product" of the rows across table. So for example, if TableF has 10 rows for id=1 and TableD has 5 rows for id=1, count will be 50, not 10, like I want.
I can easily get the right count by breaking this query into 2 queries, but I want to know is there a way to accomplish this in one query?
Thanks
I am having problems getting the right count(*) when I join two tables. See code below:
Code:
insert into #temp (id, code, frequency)
select f.id, d.code, count(*)
from TableF f
join TableD d on (f.id = d.id)
group by f.id, d.code
order by code
What I get for count(*) is the "product" of the rows across table. So for example, if TableF has 10 rows for id=1 and TableD has 5 rows for id=1, count will be 50, not 10, like I want.
I can easily get the right count by breaking this query into 2 queries, but I want to know is there a way to accomplish this in one query?
Thanks