Najam Sikander Awan

covering web stack along with microsoft technologies

Random Rows Selection From a Database Table

| Comments

hi everyone,

today I discovered a nice tip from a blog I never knew selecting random rows were that easy with sqlserver 2000 and above. I have a country table that has four countries and from 4 I am selecting random 2.

SELECT TOP 2 * FROM country ORDER By NEWID()
select * from country

First Result

3           SaudiArabia 4           France

Second Result

1           UAE 4           France

Third Result

1           UAE 3           SaudiArabia

All Countries

1           UAE 2           Pakistan 3           SaudiArabia 4           France

Amazing right??

Comments