SQL Server Performance

Tuning a query that uses Exist in the where clause

Discussion in 'SQL Server 2005 T-SQL Performance Tuning' started by WingSzeto, Apr 14, 2008.

  1. WingSzeto Member

    I am working on a old query (before my time) and am interested in a different way to make it run faster. The query is shown below. Let say I have the proper indexes for each of the tables shown. TableA is in the main join portion and also appears in the where clause.select Distinct Person_ID fromTableA a inner join TableB b on a.Request_ID = b.Request_ID inner join TableC c on a.Event_ID = c.Event_IDinner join TableD d on a.Period_id = d.Period_id AND d.Time_Begin >= '1/1/2008' AND d.Time_Begin < '3/21/2008' where (c.Location_ID = 984512 OR Exists (Select 1 From TableA er Where er.Event_ID = c.Event_ID And er.PriLocation_ID = 984512) OR Exists (Select 1 From TableE es Where es.Event_ID = c.Event_ID And es.PriLocation_ID = 984512) OR
    Exists (Select 1 from TableF wh Where wh.Event_ID = c.Event_ID And wh.Location_ID = 984512))
    Thanks in advance,wingman
  2. Adriaan New Member

    You might try UNIONing queries with the OR'ed criteria.

Share This Page