Link to home
Create AccountLog in
Avatar of jl66
jl66Flag for United States of America

asked on

How to deal with repeatedly used query within a big query?

Have the query logic below:

select some columns
from ( Query1) a, from ( Query1) b, other_tables
where some conditions including col1 <> b.col1, etc AND
other conditions including ( select col2 from  ( Query1));

In the above query, Query1 comes from expensive operations (many joins, selects, etc)
My question is
Are there ways to highly efficiently use Query1? No need to query it every time.
It seems that a temp table can be created to hold the query results.  Dear gurus, what is the best way to handle it?

 
Avatar of jl66
jl66
Flag of United States of America image

ASKER

the output from Query1 is not so big ( a few 1000s) but it involves in several big tables and many expensive operations, so I try to re-use the result but not try to re-query it many times.
SOLUTION
Avatar of gplana
gplana
Flag of Spain image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of jl66

ASKER

Excellent!! Thanks all of you so much.