I have two complex queries and I have to filter out the results from the second one, it looks something like this:
SELECT STH INTO #temp_table_1
FROM TABLE1,
TABLE2,
TABLE3
WHERE
TABLE1.ID = TABLE2.ID,
TABLE2.ID = TABLE3.ID,
TABLE3.STATUS = 'A';
SELECT STH INTO #temp_table_2
FROM TABLE1,
TABLE2,
TABLE3
WHERE
TABLE1.ID = TABLE2.ID,
TABLE2.ID = TABLE3.ID,
TABLE3.STATUS = 'B';
SELECT STH FROM #temp_table_1 t1
WHERE NOT EXIST (SELECT 1 FROM #temp_table_2 t2 WHERE t2.COL = t1.COL);
The problem is that I have to get rid of those temporary tables and write everyting in one query. But if I substitute subqueries for #temp_table_1 and #temp_table_2, it just takes too much time.
Is it possible to achieve almost the same runtime using only single query? Someone told me that I could use UNION, but didn't elaborate on that further. Is it true? This is Sybase IQ.
Asked by Quentin
(111 rep)
Jun 10, 2018, 10:12 AM
Last activity: Jun 13, 2018, 01:14 PM
Last activity: Jun 13, 2018, 01:14 PM