Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 getting top 200 while using order by newid()

Author  Topic 

csphard
Posting Yak Master

113 Posts

Posted - 2005-08-24 : 12:23:34
I am selecting the top 200 while order by newid() to get a random sample and it works. I can see that it is random because I do not get the same numbers every time. My quesetion is does the statement get the random data first and then gives me the top 200. Or am I getting the 200 and randomizing it. Since the numbers are not the same I feel it is using my criteria and then giving me the top 200 of that

sql

select top 200 e.lname,e.fname,e.empid,e.item,e.pay_location,e.sub,e.bureau,
e.division,d.eval_type
from emp_information e,due_evals d,new_organization o,new_organization n
WHERE e.deptno <> '999'
and e.empid = d.empid
and datepart(yyyy,d.todate) = '2005'
and e.empid LIKE '_[678]%'
order by NEWID()

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-08-24 : 12:34:27
order by first then top.
look at the execution plan of the query.

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -