i have two selects a & b and i join them like:
select * from
(
select n.id_b || ',' || s.id_b ids, n.name, s.surname
from names n,
surnames s where n.id_a = s.id_a
) a
left join
(
select sn.id, sn.second_name
) b on b.id in (a.ids)
in this case join doesn’t work 🙁
The problem is in b.id in (a.ids). But why if it looks like 12 in (12,24) and no result 🙁
This won’t work because
(12,24)is a single discrete string not a comma-separated set of numbers. Clearly,12 != '(12,24)', hence no results are returned.edit
I missed the outer join in your posted query. So you ought to get something back, even though there is no join between the two tables. Here is some test data:
My query is similar to yours except I cast
b.idas a string becausea.idsis a string. If I don’t do this, the query fails withORA-1722: invalid number.As you can see, it returns values from the left-hand query and nothing from the right, for the reason which I gave above.
If you want to get something from both queries on the basis on partial matching of the IDs you need to do this:
If you take this latter approach you may want to consider turning the outer join into an inner. Depnds on you precise business rule.