Random records..

This is a discussion on "Random records.." within the Databases section. This forum, and the thread "Random records.. are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Closed Thread
 
LinkBack Thread Tools
  #1  
Old Mar 4th, 2004, 08:39
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Random records..

I was looking for a way to select random records from a SQL database and come across this little beauty..

Code: Select all
SELECT
    TOP 5 *
FROM
    table
ORDER BY
    NewID()
(*) not a good idea to use *, used for the example. Always use only the fields you require.

This basically selects 5 random records from a table which you can then iterate through, bung in a recordset, etc...

This was done on MsSql, and should work on MySql and Access.

Just sharing...

u2o
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Mar 4th, 2004, 11:09
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,160
Blog Entries: 7
Thanks: 27
Thanked 19 Times in 16 Posts
Hi U2.... yeah, I use that a lot.

Doesn't work in access though to my knowledge.

Actually.... I'm gonna add this to the Articles Area.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Mar 4th, 2004, 12:15
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
tried it in Access, get the error:

Undefined function 'NewID()' in expression

Im sure theres an easy way to do this in Access tho.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Mar 5th, 2004, 15:19
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Not that easily there isn't.

Could use getRows and then output an array element based on a random number. But I don't think you can do it in a SQL statement

Or maybe get your recordset and then objRS.Move to a record between 1 and recordcount.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Mar 5th, 2004, 16:36
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah, sure you can.. I did it in an article for Rob on this very subject. I am not quite sure when the article is going to be posted, see Rob...

u2o
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Mar 5th, 2004, 17:47
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,160
Blog Entries: 7
Thanks: 27
Thanked 19 Times in 16 Posts
THe article has been added to the portal (Version 2)

Smokie... as you are an admin, you already hae access to this. Check it out.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Mar 8th, 2004, 09:31
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
nice one
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
random, records

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Multiple records jfergy Classic ASP 6 Jan 17th, 2006 16:44
ASP show records in random order therese Classic ASP 1 Jul 7th, 2005 09:34
reversing records benbacardi Classic ASP 2 Sep 4th, 2004 16:59
Delete Specific Records ekendricks Databases 1 Mar 8th, 2004 05:23
Appending multiple records jakyra Classic ASP 0 Sep 8th, 2003 19:33


All times are GMT. The time now is 22:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42