Solved

# Seleect random row using odds

Posted on 2013-06-26

Hello,

I would like to select 5 random rows from a table.

I have the columns Word, Odds. If the value in Odds is 2 it should be twice as likely to be selected when the Odds are 1. How can I select a random row that also uses odds?

here is an example:

DECLARE @Temp1 table(Word varchar(50),Odds int)

INSERT INTO @Temp1(Word,Odds)values('One',1)

INSERT INTO @Temp1(Word,Odds)values('Two',2)

INSERT INTO @Temp1(Word,Odds)values('Three',1)

INSERT INTO @Temp1(Word,Odds)values('Four',5)

INSERT INTO @Temp1(Word,Odds)values('Five',1)

INSERT INTO @Temp1(Word,Odds)values('Six',3)

INSERT INTO @Temp1(Word,Odds)values('Seven',1)

INSERT INTO @Temp1(Word,Odds)values('Eight',2)

INSERT INTO @Temp1(Word,Odds)values('Nine',1)

INSERT INTO @Temp1(Word,Odds)values('Ten',1)

INSERT INTO @Temp1(Word,Odds)values('Eleven',1)

INSERT INTO @Temp1(Word,Odds)values('Twelve',1)

SELECT * FROM @Temp1