Wednesday, March 21, 2012

Help with a query

Hello -

I am running this query in my database :

SELECT COUNT(*) AS dbCount from Item WHERE Item.Item_Category_Main = '4'

I was wondering why it was taking a long time, and then researched and found out that this causes the table to do a full table scan - this is why performance is bad.

Is there a better way to get could of the rows in a table (can't use the system table because I need the where clause)?

How can I get better performance, or do a completely different query that performs better?

Thanks for your time.

Danfor one thing, you can count a specific, preferably an indexed key column, instead of COUNT(*)sql

No comments:

Post a Comment