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
 SQL Server Development (2000)
 Retreive random record

Author  Topic 

Faiyth
Starting Member

19 Posts

Posted - 2004-10-19 : 14:45:27
What I want to do is retreive a random record from the database. Is there an easy way such as below?

select random(name) from database where name is not null order by name

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-10-19 : 15:14:29
select top 1 * from table1
order by newid()

Tara
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-10-20 : 07:10:28
...however you should not do this on a big table. ORDER BY NewID() will generate a unique identifier for each row in the table and this is time-consuming. You should limit the results by using some sort of where-clause...

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page
   

- Advertisement -