I have an inefficiently written Oracle SQL query with multiple unions of sub-queries (about 7 or 8 tables) that differ only by the table queried in sub-query, that I am certain can be written more succinctly. Observe the code at bottom, in that the only difference between the union-ed sub-queries is the table names (in this case table_a / table_b).
SELECT
/*+ parallel(10) */
Col_Alpha,
Col_Beta,
Col_Gamma,
Col_Delta,
col_epsilon
FROM
table_a
WHERE
Col_Theta = 'CAT'
And Col_Kappa In ('CAR','TRUCK','PLANE')
UNION
SELECT
/*+ parallel(10) */
Col_Alpha,
Col_Beta,
Col_Gamma,
Col_Delta,
col_epsilon
FROM
table_b
WHERE
Col_Theta = 'CAT'
AND col_kappa IN ('CAR','TRUCK','PLANE')
I tried giving a list of tables after the from clause but that did not work. I also added variations of:
from
(table_a, table_b)
And that did not work. I have tried finding a way to compress the code but I do not know enough for a successful search. I cannot use procedures with my level of access.
I expect an output similar to what I'm getting, a union of several tables with the same columns queried and same filters across all of them, but that takes around 1/7 the amount of code.