Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to optimize SQL code with IN (....)
Message
 
 
To
07/11/2005 05:40:21
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01065924
Message ID:
01065934
Views:
16
You can try JOIN.
SELECT DISTINCT p.pub_name
FROM publishers p
JOIN titles t ON p.pub_id = t.pub_id
Didi you analyze execution plan of your queries to determine what could slow them down?

>I like to know how do we optimize SQL code
>using IN into separate query from
>
>USE pubs
>SELECT pub_name
>FROM publishers
>WHERE pub_id IN <============
> (SELECT pub_id
> FROM titles
> WHERE type = 'business')
>
>Is there any better way to query the subquery first,
>then place the result inside the IN (...)
>
>Like
>
>USE pubs
>SELECT @result = pub_id
> FROM titles
> WHERE type = 'business'
>
>
>SELECT pub_name
>FROM publishers
>WHERE pub_id IN (@result)
>
>
>Since most of my SQL stored procedure is slowing down
>due to subquery. I am trying to optimize it
>and not sure why some query is working, some is halting
>my DB (lock). It does not have this problem when my
>DB size is less than 1GB.
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform