When trying to select fields from a subquery if ANY of the subqueries do not return any rows then nothing is returned (not even an empty result set)
SELECT sub1.field, sub2.another_field
FROM (
(
SELECT field
FROM table
WHERE id=1
) AS sub1, (
SELECT another_field
FROM table
WHERE id=2
) AS sub2
)
I was hoping for a row containing a NULL
value when a subquery return 0 rows.
You need to do an outer join as follows
SELECT sub1.field, sub2.another_field
FROM (
SELECT field, id
FROM tab1
WHERE id=1
) AS sub1 LEFT OUTER JOIN (
SELECT another_field, id
FROM tab1
WHERE id=2
) AS sub2
ON sub1.id = 1 and sub2.id = 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With