return empty record only when no results are returned from main query
744011Jul 7 2010 — edited Jul 8 2010This is a SQL (not PL/SQL) question...
Let's say I have the following:
SELECT NULL full_name, NULL address, NULL last_update_date
FROM dual
UNION ALL
SELECT full_name, address, last_update_date
FROM employees
WHERE TRUNC(sysdate)=TRUNC(last_update_date)
If the second part of the query retrieves no rows, this works wonderfully and I get an empty row; however, if the second part of the query returns records, I will get an empty row plus my dataset that I want.
How can I create a SQL statement that would only execute the first query (before the union all) when no results are returned from the second. Also, I don't want to exceute the query twice just so I can get a count of the records because my actual query is much more complex than the example I've provided here.
Thanks in advance!
Emily