Here's a sample table:
BookId BookTitle ------ --------------- 1 Yesterday 2 In My Life 3 Hey Junde 4 Fool On the Hill 5 If I Fell 6 Let It Be 7 Till There Was You 8 Yellow Submarine 9 I Should Have Known BetterRunning a simple TOP X% query always return the same set of records.
select TOP 30 PERCENT BookId, BookTitle from booksUsing the RAND() function always returns the same set of records:
select TOP 30 PERCENT BookId, BookTitle from books order by rand(rand(1)) BookId BookTitle ------ --------------- 1 Yesterday 2 In My Life 3 Hey JundeUsing the NEWID() function always returns a random set of records
select TOP 30 PERCENT BookId, BookTitle from books order by newid() BookId BookTitle ------ --------------- 4 Fool On the Hill 5 If I Fell 1 YesterdayHere's another run
select TOP 30 PERCENT BookId, BookTitle from books order by newid() BookId BookTitle ------ --------------- 5 If I Fell 8 Yellow Submarine 2 In My LifeSo far, I have not seen any issue using this function in a big table.
~CK
No comments:
Post a Comment