I have an issue with selecting from my subqueries. If all of the subqueries return a value, everything is fine and a row with all the values I need is returned.
However, if one subquery is null or empty, I am returned an empty set even though the other six subqueries return a value.
Why is that? How can I get around it? I tried using 'isnull' and other hacks but it didn't work. I don't understand the design and why results would be returned as an empty set if just one of the subqueries fails. What are possible workarounds?
I tried using 'UNION' but that has it's own challenges because I ideally need one row returned so that Perl/DBI can slap the results into a HASH and I can match values returned to the column name, etc.
SELECT * FROM (
(select p.pesticides from pesticides p WHERE p.id=? and p.companyid=?) AS pesticides,
(select d.directions from directions d WHERE d.id=?) AS directions,
( select i.intended from intended i where i.id=?) AS intended,
(select c.chemicals from chemicals c where c.id=? and c.companyid=?) AS chemicals,
(select a.aids from aids a where a.id=? and a.companyid=?) AS aids,
(select ing.ingredients from ingredients ing where ing.id=? and ing.companyid=?) AS ingredients,
(select s.solvents from solvents s WHERE s.id=? and s.companyid=?) AS solvents,
(select aller.allergens from allergens aller where aller.id=?) AS allergens)