A query with a left join does not return records, although a where clause from the left table should find one record. In this case, it should return a record with fields from the left table containing the values, and from the right table null, since there is no match between them.
There seems to be a problem with using a case that references the right table in a join expression.
In SQL Server, the same query worked as expected.
select t1.Description, t2.Description from A t1 left join B t2 on t1.Id = t2.Id and 1 = case when ( t2.Id = t2.Id and (select t3.Flag from C t3 where t3.ID_B = t2.Id) = 'S' ) then 1 else 0 end where t1.Id = 1
Result: no rows returned.
Then I moved the expression t2.Id = t2.Id (that is, here only to demonstrate the problem and should always return true, apparently) from the case expression.
select t1.Description, t2.Description from A t1 left join B t2 on t1.Id = t2.Id and t2.Id = t2.Id and 1 = case when ( (select t3.Flag from C t3 where t3.ID_B = t2.Id) = 'S') then 1 else 0 end where t1.Id = 1
Result: one row is returned.
The queries above are only to demonstrate the problem, are not useful in a real situation and are not optimized.
I want to know if anyone knows any Oracle limitation related to this case. So far, we believe that this is a mistake.
Used data:
- A: Id = 1, Description = Item A1;
- B: Id = 1, description = element B1;
- C: Id = 1, Id_B = 2, flag = S.
source share