Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Random selection

Reply
Thread Tools

Random selection

 
 
Jamie Fryatt
Guest
Posts: n/a
 
      11-28-2003
Hi all, im a little bit new to all this so i you could help me a little i
would be greatful.

How do i select a completly random record from a database?

sql = select (random) from tbl, sort of thing.

Thanks for any help you can give

Jamie


 
Reply With Quote
 
 
 
 
Graham Mattingley
Guest
Posts: n/a
 
      11-28-2003
Hi Jamie,

is it ASP ???

you could do something like

select count(*) from tbl, sort of thing

randomize
count = {count varable from select (*)}
random_number=int(rnd*count)+1

select from tbl where id = random_number

something like this will do it

Graham





"Jamie Fryatt" <(E-Mail Removed)> wrote in message news:bq7kql$64o$(E-Mail Removed)...
> Hi all, im a little bit new to all this so i you could help me a little i
> would be greatful.
>
> How do i select a completly random record from a database?
>
> sql = select (random) from tbl, sort of thing.
>
> Thanks for any help you can give
>
> Jamie
>
>

 
Reply With Quote
 
 
 
 
PL
Guest
Posts: n/a
 
      11-28-2003
> How do i select a completly random record from a database?

The question is what kind of database ? Some databases actually
have a way of doing it directly, if it's SQL server you need to fool
it a bit and the code is not that efficent:

"SELECT TOP 1 [fieldname] from [yourtable] order by newid()"

PL.


 
Reply With Quote
 
MePadre
Guest
Posts: n/a
 
      11-28-2003
Forgive me if I am wrong, but does your suggestion not
require that all the IDs be sequential. If, for instance
you started with 200 records, and deleted every other one,
you would be left with 100 even numbered records. Using
your logic, the count would be 100 and the random_number
might be odd (i.e. 33). Since there is no record ID 33
(remember all odd records were deleted), the query would
return nothing.


>Hi Jamie,>select count(*) from tbl, sort of thing
>
>randomize
>count = {count varable from select (*)}
>random_number=int(rnd*count)+1
>
>select from tbl where id = random_number



>-----Original Message-----


>
>is it ASP ???
>
>you could do something like
>


>
>something like this will do it
>
>Graham
>
>
>
>
>
>"Jamie Fryatt" <(E-Mail Removed)> wrote in

message news:bq7kql$64o$(E-Mail Removed)...
>> Hi all, im a little bit new to all this so i you could

help me a little i
>> would be greatful.
>>
>> How do i select a completly random record from a

database?
>>
>> sql = select (random) from tbl, sort of thing.
>>
>> Thanks for any help you can give
>>
>> Jamie
>>
>>

 
Reply With Quote
 
Jamie Fryatt
Guest
Posts: n/a
 
      12-01-2003
i am using a standard ms access database!

i just need a select statement for a random record select if there is one?

Thanks

Jamie


"PL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > How do i select a completly random record from a database?

>
> The question is what kind of database ? Some databases actually
> have a way of doing it directly, if it's SQL server you need to fool
> it a bit and the code is not that efficent:
>
> "SELECT TOP 1 [fieldname] from [yourtable] order by newid()"
>
> PL.
>
>



 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      12-01-2003
Jamie Fryatt wrote:
> i am using a standard ms access database!
>
> i just need a select statement for a random record select if there is
> one?
>

http://groups.google.com/groups?hl=e...se&sa=N&tab=wg

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
 
 
Reply

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
JTable with row selection, but no cell selection Simon Niederberger Java 2 01-07-2005 04:17 PM
JS comparing innerHTML to text selection (window.getSelection() /document.selection) Andrew Crowe HTML 1 09-13-2004 02:22 PM
HOWTO autopost the selection list upon selection curiousity ASP .Net Mobile 0 11-21-2003 12:57 AM



Advertisments