Click here to Skip to main content
15,898,770 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Select query is taking too much query on orderby clause

can anyone kindly help me with this. Please find the code below.

SELECT * FROM tblQ ORDER BY QCDate DESC

QCDate is a date column
table consists of only four rows and this query is taking 25sec.
Posted
Comments
[no name] 6-Nov-12 3:37am    
How many records u have in this table..??
saiteja45 6-Nov-12 4:07am    
four
Bala Selvanayagam 6-Nov-12 4:02am    
Could be your computer is low spec ?
saiteja45 6-Nov-12 4:09am    
I am using I5 processor... I dont think the problem is with my computer as other queries are running quick. only if I add orderby clause it is slowing down....

1 solution

The problem is that this could be anything at this stage.
Start small and reduce your query to it's most basic:
SQL
SELECT QCDate FROM tblQ ORDER BY QCDate DESC
If this still takes 25 seconds, then remove the "ORDER BY" part and try again.If that is still slow, then you need to look ate you SQL server installation - there is probably a problem.

Once you have a fast query, you can add bits back until you have the complete query again, or adding one element slows it down.
 
Share this answer
 
Comments
saiteja45 6-Nov-12 4:06am    
@OriginalGriff
Thanks for immediate response. I already tried removing orderby clause, it is taking less than a second. but i need to add orderby.. :(
OriginalGriff 6-Nov-12 4:13am    
Did you get any difference when you restricted it to just the one field returned?
saiteja45 6-Nov-12 4:23am    
When I executed to one field, first it took 12 sec.... after that it is taking the same(25 sec).

But if I use primary column as orderby it is executing super fast... may I know the difference
OriginalGriff 6-Nov-12 4:36am    
Have you tried adding an index on QCDate?
For four rows 12 secs is still ridiculous!
How much stuff do you have in the rest of the DB? How many users are on teh same SQL server instance?
saiteja45 6-Nov-12 6:11am    
We are two users working on it.
regarding indexing... do db sort the rows based on indexes... as it has to sort by the content I dont think it will affect my query.

Ill try to do indexing as well and will post the result soon.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900