By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE table_a (column_a INT);
SELECT *
FROM (
SELECT column_a,
CASE WHEN column_a > 10 THEN 0 ELSE 1 END AS column_b
FROM table_a
UNION ALL -- Use UNION ALL to keep duplicates from table_a.
SELECT -1,-1 FROM DUAL -- Use the DUAL table which always has exactly 1 row.
)
WHERE column_b >= 0 -- All the rows from table_a, if any exist.
OR ROWNUM = 1 -- Or, just the first row.
;
COLUMN_A | COLUMN_B |
---|---|
-1 | -1 |
INSERT INTO table_a (column_a)
SELECT 1 FROM DUAL UNION ALL
SELECT 2 FROM DUAL UNION ALL
SELECT 6 FROM DUAL UNION ALL
SELECT 10 FROM DUAL UNION ALL
SELECT 11 FROM DUAL UNION ALL
SELECT 11 FROM DUAL UNION ALL
SELECT 15 FROM DUAL;
7 rows affected
SELECT *
FROM (
SELECT column_a,
CASE WHEN column_a > 10 THEN 0 ELSE 1 END AS column_b
FROM table_a
UNION ALL -- Use UNION ALL to keep duplicates from table_a.
SELECT -1,-1 FROM DUAL -- Use the DUAL table which always has exactly 1 row.
)
WHERE column_b >= 0 -- All the rows from table_a, if any exist.
OR ROWNUM = 1 -- Or, just the first row.
;
COLUMN_A | COLUMN_B |
---|---|
1 | 1 |
2 | 1 |
6 | 1 |
10 | 1 |
11 | 0 |
11 | 0 |
15 | 0 |