I have three tables
Table T1: Columns {a,b,c}, combination {a,b} is unique in Table T1
Table T2: Columns {a,c,d}, combination {a,c} is unique in Table T2
Table T3: Columns {a,c,e}, combination {a,c} is unique in Table T3
where {a,b,c} are strings and {d,e} are numbers
I want my output to be
Table T4: Columns {a,b} where e/d < x.
Tables T1,T2,T3 are all very large (millions of rows), so the way I implemented this is by doing an left join on table T1 T2 and saving the results to a temp table, then doing an left join on tables T1 T3 and saving the results, then doing an left join of the results and finally combining these temp tables into 1 final table.
My question is, is there a better/more efficient way to do this without blowing up the database?
Have you tried just doing this the straight-forward way?
Storing millions of records in temp tables isn’t good for performance or storage…