Subject Re: [ib-support] Self left join
Author Arno Brinkman
Hi,

> I would like a list of all products from account_id = 1, and those
matching
> products from account_id = 2. The following query only returns matching
> products, not the complete list of products from the first account_id:
>
> select
> p1.name, p2.name
> from
> products p1
> left join products p2 on (p2.name = p1.name)
> where
> p1.account_id = 1 and
> p2.account_id = 2

> Is this not possible? I know that if there was a Product1 and a Product2
> table, the left join would work correctly.

select
p1.name, p2.name
from
products p1
left join products p2 on (p2.name = p1.name and p2.account_id = 2)
where
p1.account_id = 1

Regards,
Arno Brinkman