Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Improve SQL query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-28 : 10:05:30
Kee writes "Hello,

I'm having problems with the used of "EXISTS"

I try to do my code using OR instead of AND, the output result is slow.

Here is my code:

SELECT distinct p.product_id
FROM product p, org o, product_membership pm, product_event_dates ped
WHERE p.product_id *= pm.product_id
and p.org_id = o.org_id
and p.product_id *= ped.product_id
and o.state = 'WA'
AND (exists (SELECT (1) FROM product_activities pal
WHERE pal.activity = 'Adventure'
AND p.product_id = pal.product_id)
OR exists (SELECT (1) FROM product_tariff_season_tact ptst
WHERE ptst.activity = 'Adventure'
AND p.product_id = ptst.product_id)
)
AND p.product_id < 5000

Once I remove the code:

OR exists (SELECT (1) FROM product_tariff_season_tact ptst
WHERE ptst.activity = 'Adventure'
AND p.product_id = ptst.product_id)

it seen to excute faster.
How can I improve this code so that the query time can be faster.
Cheers

Kee"
   

- Advertisement -