Subject Re: [firebird-support] Firebird Inner Join And SubSelect
Author Svein Erling Tysvaer
Assuming the combination vatcode, vatvalue and netvalue is unique, your
select can be simplified, making the derived table unneccessary:

select
v.vatcode,
sum(d.netvalue) as disbs
v.vatvalue,
v.netvalue
from vattransactions v
join disbursements d on v.transno = d.transno
where v.vatquarter = 20
and v.inputoutput = 'O'
group by
v.vatcode, v.vatvalue, v.netvalue
order by
v.vatcode

HTH,
Set

martinthrelly wrote:
> hi i am trying to run the following sql within IBExpert but it wont
> run saying "invalid token Select". i realise this may be a simple
> error i am making but could somebody please point me out why i cannot
> join a summed amount like this. thanks.
>
> select
> v.vatcode,
> d.disbs,
> v.vatvalue,
> v.netvalue
> from vattransactions v
> inner join (
> select
> sum(netvalue) as disbs
> from disbursements) d on v.transno = d.transno
> where v.vatquarter = 20
> and v.inputoutput = 'O'
> order by
> v.vatcode