Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Random select

 
   Database Help (Home) -> mySQL RSS
Next:  Convert Linux flatfile auth to mysql db backend  
Author Message
wimroffel

External


Since: Jan 09, 2005
Posts: 2



(Msg. 1) Posted: Wed Feb 16, 2005 1:08 pm
Post subject: Random select
Archived from groups: mailing>database>mysql (more info?)

Hi,

When I do a select with a limit I get always the same records. Usually this
is the desidered effect.

But now I want to do a random select. So every time I do a select I should
get a different set of results.

What is the best way to achieve this effect?

Thanks,
Wim

 >> Stay informed about: Random select 
Back to top
Login to vote
user2734

External


Since: Jan 06, 2005
Posts: 28



(Msg. 2) Posted: Wed Feb 16, 2005 1:56 pm
Post subject: Re: Random select [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Wim Roffil wrote:
 > Hi,
 >
 > When I do a select with a limit I get always the same records. Usually this
 > is the desidered effect.
 >
 > But now I want to do a random select. So every time I do a select I should
 > get a different set of results.
 >
 > What is the best way to achieve this effect?
 >
 > Thanks,
 > Wim
 >
 >

What is your problem? Do you really want random records, or are you
bothered that you get the same records everytime you perform a select?

If its the latter, you should use a WHERE clause in your SELECT and
perhaps also a LIMIT start,rows

Thus,something like

SELECT firstname,lastname FROM myTable WHERE ID>10 LIMIT 5,12

will find all records that have ID>10 and return 12 records, starting
from the 5th one found (thus something like records with ID 15 to 27).

If you want to read random records, request a random record (I'm
assuming you've got a column/cell that is AUTO_INCREMENT that you could
use as reference).

Does that help you any?
randelld

 >> Stay informed about: Random select 
Back to top
Login to vote
wimroffel

External


Since: Jan 09, 2005
Posts: 2



(Msg. 3) Posted: Wed Feb 16, 2005 4:40 pm
Post subject: Re: Random select [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Randell D." schreef in
bericht
 > Wim Roffil wrote:
  > > Hi,
  > >
  > > When I do a select with a limit I get always the same records. Usually
this
  > > is the desidered effect.
  > >
  > > But now I want to do a random select. So every time I do a select I
should
  > > get a different set of results.
  > >
  > > What is the best way to achieve this effect?
  > >
  > > Thanks,
  > > Wim
  > >
  > >
 >
 > What is your problem? Do you really want random records, or are you
 > bothered that you get the same records everytime you perform a select?

Thank you for your reply.

I need reaaly random records. From a big collection I want to show the
visitors of my webpage just 5 or 10. Because adjacent records may be related
they should be spread over the whole collection. AUTO_INCREMENT is not an
option: it is not already there and the query is not over the whole table
but over a part of it (there is a WHERE clause).

 >
 > If its the latter, you should use a WHERE clause in your SELECT and
 > perhaps also a LIMIT start,rows
 >
 > Thus,something like
 >
 > SELECT firstname,lastname FROM myTable WHERE ID>10 LIMIT 5,12
 >
 > will find all records that have ID>10 and return 12 records, starting
 > from the 5th one found (thus something like records with ID 15 to 27).
 >
 > If you want to read random records, request a random record (I'm
 > assuming you've got a column/cell that is AUTO_INCREMENT that you could
 > use as reference).
 >
 > Does that help you any?
 > randelld
 >> Stay informed about: Random select 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
generating a random number - is it possible to generate a random number within an sql script rather than the client specifying which random row to select?

Select more than just * - Is it possible to run a query like this: SELECT *, DATEDIFF(CURDATE(), `updated`) AS `daysSinceUpdate` FROM `Admin` Or should I let PHP calculate the days since update?

select with regexp - i have a column "path" with values eg. +---------------+ | path | +---------------+ |/path/path/path| +---------------+ |/path/path | +---------------+ |/path | +---------------+ i want to select the row where there are ...

Select Query Help - I'm struggling - with my limited knowledge of SQL - to write a query that does what I want it to, and I was hoping that someone here may be able to help out. I have a table with two columns, user1 and user2, which store user ID's. For example: ..

Count lines in select - I have a table t1: id int unique added timestamp and second table t2: eid int id int unique t2.id are IDs from t1. t2.eid with the same value can be found in t2 more than for one entry but they will all have different IDs. I want to: ..
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]