Hi,
I'm trying to retrieve a list from one table joined to the same table with separate aliases. Data in the table is follows:
table1
-------
category subcategory
-------- -----------
112 1
112 2
112 3
112 4
112 5
113 1
113 2
Desired Result:
I would like the query to return those with whose value is category 112 but the subcategory does not exist in value 113. Thus,
category subcategory
-------- -----------
112 3
112 4
112 5
I'm trying to accomplish this using a "left outer join" to the same table:
select z1.category, z1.subcategory, z2.category, z2.subcategory
from table1 z1 left outer join table1 z2 on z1.subcategory = z2.subcategory
where z1.category = 112
and z2.category = 113
However, this query returns the intersection:
112 1 113 1
112 2 113 2
When I run the sql the "old-fashion-way", using an outer join(code: *= ), it's coming up correctly:
select z1.category, z1.subcategory, z2.category, z2.subcategory
from table1 z1 , table1 z2
where z1.subcategory *= z2.subcategory
and z1.category = 112
and z2.category = 113
Result:
category subcategory
-------- -----------
112 3
112 4
112 5
Can somebody point out the differences, please. I thought that the two sqls would return the same thing. And also, can someone tell me what should be the "outer join" equivalent of the last sql?
Thanks a lot,
Tina
I'm trying to retrieve a list from one table joined to the same table with separate aliases. Data in the table is follows:
table1
-------
category subcategory
-------- -----------
112 1
112 2
112 3
112 4
112 5
113 1
113 2
Desired Result:
I would like the query to return those with whose value is category 112 but the subcategory does not exist in value 113. Thus,
category subcategory
-------- -----------
112 3
112 4
112 5
I'm trying to accomplish this using a "left outer join" to the same table:
select z1.category, z1.subcategory, z2.category, z2.subcategory
from table1 z1 left outer join table1 z2 on z1.subcategory = z2.subcategory
where z1.category = 112
and z2.category = 113
However, this query returns the intersection:
112 1 113 1
112 2 113 2
When I run the sql the "old-fashion-way", using an outer join(code: *= ), it's coming up correctly:
select z1.category, z1.subcategory, z2.category, z2.subcategory
from table1 z1 , table1 z2
where z1.subcategory *= z2.subcategory
and z1.category = 112
and z2.category = 113
Result:
category subcategory
-------- -----------
112 3
112 4
112 5
Can somebody point out the differences, please. I thought that the two sqls would return the same thing. And also, can someone tell me what should be the "outer join" equivalent of the last sql?
Thanks a lot,
Tina