EDIT: Far simpler example. (Formerly titled: Oracle Column Injection)
GOAL: Complete the query below generate the following results?
PURPOSE: Create a column dependent on an existing column in a table without putting the table in a subquery.
Rules:
- Restructuring the query to put
tbl
in a subquery is not an option. - The query must use
a,b->1; x->2; y->3
, not simply join to1,1,2,1,3
. - The subquery
tbl
must not be modified.
SELECT val, cat
FROM (SELECT 'a' val FROM DUAL UNION ALL
SELECT 'b' val FROM DUAL UNION ALL
SELECT 'x' val FROM DUAL UNION ALL
SELECT 'b' val FROM DUAL UNION ALL
SELECT 'y' val FROM DUAL) tbl
... JOIN ( ... ) ON ...
val | cat
-----+-----
'a' | 1
'b' | 1
'x' | 2
'b' | 1
'y' | 3
Well, I got this far (below), but I cannot add a second LEFT JOIN.
SELECT val, cat
FROM (SELECT 'a' val FROM DUAL UNION ALL
SELECT 'b' val FROM DUAL UNION ALL
SELECT 'x' val FROM DUAL UNION ALL
SELECT 'b' val FROM DUAL UNION ALL
SELECT 'y' val FROM DUAL) tbl
LEFT JOIN ( SELECT 1 cat FROM DUAL ) ON val in ('a','b')
val | cat
-----+-----
'a' | 1
'b' | 1
'x' |
'b' | 1
'y' |