Is there a way to store a table in a temporary variable in SQL to reuse it many times within the statement??
-> I use MySQL.
I generate a table "y" by means of quite a large SQL query.
Now I need to perform many SELECT, UNION statements on that table, meaning:
SELECT a,b,c
FROM y
UNION
SELECT d,e,f
FROM y
UNION
SELECT g,h,i
FROM y
UNION....
.... and so on. Of course oversimplified.
For now, instead of the "y", I copy pasted the SQL Statement that produces "y" into all these steps, resulting in the overall query being extreeeeeeemely inflated.
Is there a way to store a produced table in a temporary variable??
Would appreciate your help so much.
I tried to create a temporary table as an example but it fails: