Link to home
Start Free TrialLog in
Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on

sql count

I need to know the number of occurrences of orderid in that occurs in a separate table

I had been using

SELECT   count(orderid)
            FROM vDirectMail_Incentive_MailHouseFile_December2015 WHERE orderId IN (
                        SELECT orderid
                        FROM orders)

This used to work great but recently it seems to hang

Any suggestions on alternatives????
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnnyg123

ASKER

Unfortunately,

query never completes (used to take a few seconds but I've let it go 30 minutes and still nothing) so I can't get the query plan
exec sp_who2 to see if you have any blocking going on.  You can run it from another connection while the query is "locked up".
You could use the table hint "with nolock"

Table hints aren't recommended but they can bail you out occasionally.

For example: select * from myTable with nolock
Thanks all

I thought I had put nonclustered index for order id  but apparently I had not

As soon as I added one, all is well
Thanks for the split.  Good luck with your query.  -Jim

btw which table did you add a nonclustered index for order id?  I would think that an orders table would have OrderID as a clustered primary key.