I have a SQL query which takes much time to execute (like 30 minutes!) due to the huge data it takes.
However, I need to do a couple of things more on this result a self join on this query.
I can't create a temporary table on this database.
What I want is a way to do this self join without executing this query twice.
Is there a way to write a main query (maybe with the 'WITH' syntax) to allow that?
Edit: Here is a sample of what would work:
With
MyQueryAlias1 AS
(30 minutes sql query here)
MyQueryAlias2 AS
(30 minutes sql query here)
SELECT
MyQueryAlias1.field1
FROM
MyQueryAlias1
JOIN MyQueryAlias2
ON MyQueryAlias1.field2 = MyQueryAlias2.field3
This is just an example but it shows that the "30 minutes sql query here" will be executed twice, which is my problem.