Monday, March 26, 2012

order by issue

I'm trying to get a query to work that specifies how many records to return
(TOP(###)) and order them by one of the columns in the table. What I'm
getting is a server timeout.
My query looks kinda like this "select top(500) * from mytable order by
mycolumn"
I've tried this on a couple of different servers with the same timeout
error.
Any Ideas on how to fix?
How many rows are in the table? Is there an index on mycolumn?
"Jimmy Stewart" <jstewart@.globalparadigmsolutions.com> wrote in message
news:u7RQrc1mIHA.4292@.TK2MSFTNGP04.phx.gbl...
> I'm trying to get a query to work that specifies how many records to
> return
> (TOP(###)) and order them by one of the columns in the table. What I'm
> getting is a server timeout.
> My query looks kinda like this "select top(500) * from mytable order by
> mycolumn"
> I've tried this on a couple of different servers with the same timeout
> error.
> Any Ideas on how to fix?
>
|||There are something over 1.2 million records (rows) in the table.
No the column is not indexed.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:F3DD40E4-5AF5-4392-8A0D-A09AEC62FF14@.microsoft.com...
> How many rows are in the table? Is there an index on mycolumn?
>
> "Jimmy Stewart" <jstewart@.globalparadigmsolutions.com> wrote in message
> news:u7RQrc1mIHA.4292@.TK2MSFTNGP04.phx.gbl...
>
|||In that case, each query requires a full table scan to determine the 500
rows you want to select.
Either increase the connection timeout or (preferably) add proper
indexes.
Also, it is best to only select the columns that you need, and thus
avoid SELECT *
Gert-Jan
Jimmy Stewart wrote:[vbcol=seagreen]
> There are something over 1.2 million records (rows) in the table.
> No the column is not indexed.
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:F3DD40E4-5AF5-4392-8A0D-A09AEC62FF14@.microsoft.com...

No comments:

Post a Comment