A query returns multiple rows in some environments but returns 0 rows in the other environments. I want to know all results in one output in the same format, so I wrote the query below. However, it works as I intended when the former part of the query returns 0 rows, but when it returns some rows, it returns an extra row. How to not show the latter query result when the former query returns rows?
SELECT
id, name
FROM
members
WHERE
some_condition_goes_here
UNION
SELECT 0 as id, 'No results' as name FROM DUAL
Actual results:
| id | name |
|---|---|
| 0 | No results |
| id | name |
|---|---|
| 1 | John |
| 6 | Kate |
| 0 | No results |
The last row (id = 0) is not needed in this case.
Expected results:
| id | name |
|---|---|
| 0 | No results |
or
| id | name |
|---|---|
| 1 | John |
| 6 | Kate |