I am using postgres.
What I have right now is like this:
SELECT <statement> FROM (
<MASSIVE JOIN STATEMENT>
)
UNION ALL
SELECT <different statement> FROM (
<SAME MASSIVE JOIN STATEMENT>
)
What I would really like is to have is a way to accomplish the same thing without having to put in the same massive join statement multiple times. Is there a way to accomplish this?
Thank You!!
I tried giving the table an alias and referencing the alias in the second SELECT statement, but it didn’t work. Postgres says the relation does not exist.
>Solution :
Given its the same source for both selects, have you tried using a CTE?
e.g:
WITH CTE AS (
-- Your MASSIVE JOIN STATEMENT here
)
SELECT <statement> FROM CTE
UNION ALL
SELECT <different statement> FROM CTE;