Subject Re: [ib-support] Join Table with self
Author Jason Chapman (JAC2)
> Is it possible to join a table with itself as follows:-
>
> 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.
If for each TransRef there are 2 rows, you will end up with 4 ( I think)
rows (If you had no other criteria. The growth is exponencial. I am
assuming that TransRef is not the PK, but a grouping mechanism for entries
in a double entry ledger. I can't see whay you would want to do this, is it
to get all entries that are involved in a transaction that refers to Actn =
'C'?

I would probably do this as
Select * from GenLedger where Tranref in (select Tranref from GenLedger when
Actn = 'C') Especially if Actn does not have an index on it.

What do the two different Q's return as a plan?

JAC