This one is slow and I know it can be optimized, anybody who have ideas on what should I change? TIASELECT table1.REFERENCE, table2.Column2, table2.Column3, table2.Column4 FROM table1 INNER JOIN table2 ON table1.REFERENCE = table2.REFERENCE WHERE ( table2.LinkedReference = @whereReference) OR ( table2.REFERENCE IN ((SELECT table1.table2_REF FROM table1 INNER JOIN table3 ON table1.REFERENCE = table3.REFERENCE WHERE ( table3.LinkedReference = @whereReference) OR ( table3.REFERENCE IN (SELECT REFERENCE FROM table5 WHERE LinkedReference = @whereReference) ) OR ( table3.REFERENCE IN (SELECT table3_REF FROM table6 WHERE LinkedReference = @whereReference) ) OR ( table3.REFERENCE IN (SELECT REFERENCE FROM table7 WHERE LinkedReference = @whereReference) ) OR ( table3.REFERENCE IN (SELECT REFERENCE FROM table8 WHERE LinkedReference = @whereReference) ))) ) OR ( table2.REFERENCE IN (SELECT REFERENCE FROM table9 WHERE LinkedReference = @whereReference) ) AND TYPE = 'L' AND table2.MarkedForDeletion = 'N' AND table1.REFERENCE NOT IN (SELECT REFERENCE FROM table1 WHERE CATEGORY = 'x')