Select 10 Random Records

How to write a query in SQL 2005 in order to Select 10 random records from table?

Questions by hossein

Showing Answers 1 - 15 of 15 Answers

smonroy

  • Sep 26th, 2011
 

SELECT TOP 10 * FROM TABLE_NAME ORDER BY NEWID()
EXAMPLE:
select top 10 * from cars order by newid()
ID CAR DESCRIPTION
504 CARRO 77 CARRO DE CHASIS
501 CARRO 74 CARRO DE CHASIS
46 CARRO 45 CARRO 45
526 CARRO 99 CARRO DE CHASIS
37 CARRO 36 CARRO 36
498 CARRO 70 CARRO DE CHASIS
40 CARRO 39 CARRO 39
44 CARRO 43 CARRO 43
473 RACK 160 RACK 160
24 CARRO 23 CARRO 23

  Was this answer useful?  Yes

ASHOK PANGULURI

  • Feb 11th, 2012
 

Code
  1. SELECT * FROM emp WHERE rownum>=10 ORDER BY empno;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions