Due to some dynamic SQL complications, I have a need to join two tables together and query from the result as if it were a single table. The twist is that I have to SELECT *
on the inner query -- I can't alias the columns. There seems to then be no way to identify those columns in the outer query.
Take for example these tables
CREATE TABLE test_tab1 (join_key NUMBER, tab1_uqcol VARCHAR2(30));
CREATE TABLE test_tab2 (join_key NUMBER, tab2_uqcol VARCHAR2(30));
INSERT INTO test_tab1 VALUES (1, 'table 1 only');
INSERT INTO test_tab2 VALUES (1, 'table 2 only');
I can easily enough filter on their unique columns
SELECT *
FROM (
SELECT *
FROM test_tab1 t1
INNER JOIN test_tab2 t2
ON t1.join_key = t2.join_key
) joined
WHERE tab1_uqcol LIKE 'table%';
but if I try to refer to a column they have in common...
SELECT *
FROM (
SELECT *
FROM test_tab1 t1
INNER JOIN test_tab2 t2
ON t1.join_key = t2.join_key
) joined
WHERE join_key = 1;
then it tells me that join_key
is an invalid identifier. Ditto t1.join_key
, test_tab1.join_key
, "t1.JOIN_KEY"
, "T1.JOIN_KEY"
, and "TEST_TAB1.JOIN_KEY"
. How do I identify these star-selected columns?