Groups | Blog | Home
all groups > sql server programming > december 2003 >

sql server programming : Select top 1 hangs, but select top 2 no problem!


ck
12/12/2003 9:26:37 PM
I am doing a relatively straightforward select top 1 against a few joined
tables, select involves some text e.g.

select top n 'Name: ' + name from table1 join table2...

When I select the top 2, 3, 5, 100, etc, it comes back no problem, but
select top 1 hangs indefinitely! (I end up cancelling I'm running through
Query Analyzer). What could be up?

Thanks,

Chris

Aaron Bertrand [MVP]
12/12/2003 9:59:04 PM
Do you have an ORDER BY clause?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




[quoted text, click to view]

ck
12/13/2003 7:40:38 AM
No. This would return an error.

[quoted text, click to view]

Aaron Bertrand [MVP]
12/13/2003 9:00:16 AM
(a) you can't really expect consistent results if you use TOP without an
ORDER BY. The row(s) returned will be arbitrary.

(b) what error???

Maybe instead of narrative, you could show your table structure, the actual
query, desired results, and enough sample data to reproduce the problem?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




[quoted text, click to view]

AddThis Social Bookmark Button