Subject | Self left join |
---|---|
Author | Bob Murdoch |
Post date | 2003-04-10T21:15:29Z |
Given a table with a structure like this:
create table Product(
id integer,
account_id integer,
name varchar(40));
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.
Using FB1 on W2k.
tia,
Bob M..
create table Product(
id integer,
account_id integer,
name varchar(40));
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.
Using FB1 on W2k.
tia,
Bob M..