Friday, January 27, 2012

Get Random record

Que : How To get  Random Record every time from a table using a single query ?

create table _record
(
   id int identity(1,1),
   name varchar(15),
  address varchar(15)
)

insert into _record values('naimish','Gondal')
insert into _record values('vimal','Devchadi')
insert into _record values('jugal','junagadh')
insert into _record values('ravi','Amreli')
insert into _record values('Bhadresh','Bhader')
insert into _record values('Mohit','Rajkot')



1 comment:

  1. Gives a single random record every time from table
    you can see exactly output if hundreds of records in table.
    -> select top 1 * from _record order by NEWID()

    ReplyDelete