Subject | Re: [ib-support] Join Table with self |
---|---|
Author | Arno Brinkman |
Post date | 2002-06-12T14:42:01Z |
Hi,
Try this (untested ofcourse):
SELECT
a.Transfer,
b.Amount,
b.Actn,
a.Accountid,
b.Accountid
FROM
GenLedger a
JOIN GenLedger b ON (a.TransRef = b.TransRef AND b.Actn='C')
WHERE
a.accountid = 'Bank1'
Regards,
Arno
> Is it possible to join a table with itself as follows:-its
> SELECT * FROM GenLedger a
> JOIN GenLedger b ON a.TransRef = b.TransRef
> AND a.Actn='C'
>I run out of memory when I run this query.
>All records forming a transaction are linked together via a field called
>transref.
>ATable
>transref amount actn accountid
>001 30.00 'C' 1232345
>001 10.00 'D' EBFS
>001 20.00 'D' Bank1
>What I want is all records = 'Bank1' with the corresponding 'C' linked via
>the transref. Effectively what I want to do is a left join of a table on
>self for a select record value. I want the accountid1,When i understand you your first query was almost good except the join part.
>accountid2 values in the same row(ie the association) done via SQL.
>The result I want from the above table is:-
>transref amount actn accountid1 accountid2
>001 30.00 'C' Bank1 1232345
>I hope this explains my needs.
Try this (untested ofcourse):
SELECT
a.Transfer,
b.Amount,
b.Actn,
a.Accountid,
b.Accountid
FROM
GenLedger a
JOIN GenLedger b ON (a.TransRef = b.TransRef AND b.Actn='C')
WHERE
a.accountid = 'Bank1'
Regards,
Arno