Could you please help me in simplifying and reducing the cost of the below query?
I tried making it a co-related subquery with NOT EXISTS but it didn’t give me any output.
Please note that the table in both main and inner query is the same ‘table_1″.
SELECT *
FROM Table_1 A
WHERE A.Col1 = 'abcd'
AND (A.Col2, A.Col3) NOT IN
(SELECT Col2,
Col3
FROM Table_1 B
WHERE (B.Col4 IN (1,2,3)
And B.Col5 In ('x','y'))
OR (B.Col4 = 1 AND B.Col5 = 'z' AND B.Col6 = 'f')
))
Thanks in advance,
Savitha
Usually its a lot about trial and error. In addition to using the not exists and outer join, since this is a self-join, it should reduce down to a single table…
Or you could try using a MINUS…
The most efficient solution will depend on the spread of the data.
Are you sure there are matching rows?