Subject Re: [firebird-support] Re: question about joins
Author Michael Weissenbacher
Hi,
> Nope, it depends on the number of matching records in the other
> table(s). With his example:
> ...
> To get the sum of the individual table, he would want sum(s.sales)/3 and
> sum(c.costs)/2.
Ooops, sorry, you are right. I guess my mind went the wrong way when I
thought that up. Pity that I can't withdraw yesterday's mail now without
a time machine :)

> select m.id, sum(s.sales)/(select count(*) from coststable c2
> where c2.id = m.id), sum(c.costs)/(select count(*) from salestable s2
> where s2.id = m.id)
> from maintable m
> left join salestable s on s.id = m.id
> left join coststable c on c.id = m.id
> where m.id = 1
> group by m.id
>
> Though I cannot think of any situation where this would be preferrable
> to a simple subselect.
Exactly, thanks for the clarification. Subselects or 2 seperate selects
would be the way to go then.

Michael