开发者

Informix query oddities

开发者 https://www.devze.com 2023-01-14 05:00 出处:网络
I am running 2 queries against an Informix database.The queries are hitting 4 different tables with both inner and outer joins.I thought they should both return the same result set, but I am getting a

I am running 2 queries against an Informix database. The queries are hitting 4 different tables with both inner and outer joins. I thought they should both return the same result set, but I am getting a 3 record difference. The two queries are shown below:

query 1 (returns 65 rows) -

 select ...  
    from table1, table2, outer table3, outer table4
   where table1.id = table2.id
     and table1.id = table3.id
     and table1.id = table4.id 
     and .....

query 2 (returns 62 rows) -

select ....
from table1 inner join table2 on table1.id = table2.id
left outer join table3 on table1.id = table3.id
left outer join table4 on table1.id = table4.id
where .....

Does anyone have any idea why these 2 return different result sets? I assumed that by changing to use inner join / left outer join instead of jus开发者_运维知识库t using outer (and nothing for the inner join) would return the same results.


The contents of the WHERE clauses are probably a factor in this. The first notation, the Informix-style OUTER join notation, is non-standard, and has rather peculiar semantics (that's being polite). The second notation is the ISO standard OUTER JOIN which has prescribed semantics.

With the Informix-style join, all the rows from the inner-joined pair of tables that survive any filters in the WHERE clause that are on their columns only will be returned in the result set. If there are filters in the WHERE clause on columns in the outer-joined tables, or between the inner tables and the outer tables, then those filters may eliminate some possible rows from the result set, but the innner-joined part of the result will still appear extended with nulls. It is excruciatingly complex to explain. It sort of more or less makes sense, but the result isn't simply a projection of a restriction of the basic set of joins.

Can you confirm that the WHERE clauses contain some conditions on columns in table3 and table4?

There isn't a trivial way to simulate the Informix-style OUTER join with ISO standard OUTER JOIN notation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号