Randomization

A

Anonymous

Guest
I've got a database full of word definitions. I would like to move the table in the mysql database, or the data inside it, to another table, except I would not like to put it in the same order as it's in currently. I want to be able to access it randomly.
 
Part of the definition of the relational data is that there is no order. Often people ask how to change the order of items in a database. But in a true relational database (that includes MySQL, PostgreSQL, MSSQL, etc.), there's no order, and the order that items come out when you do, say, a SELECT, is just a matter of happenstance, so to try to change the order is folly. This is true for the order of both rows and columns.

That said, to grab a random row from a MySQL database, just use the ORDER BY RAND() clause, e.g.:

Code:
SELECT column FROM table ORDER BY RAND() LIMIT 1;
 
I'm kinda confused. See... I put the objects in order by giving each word a number id. I'll try what you said and maybe that'll work, but I'm still kinda confused.

BTW, if I say that the limit is the number of items in the table, will it select every single item once, or some itmes some times and some items other times?
 
LIMIT a,b
means start from index 'a' and give back 'b' no of records
so if
Code:
SELECT column FROM table ORDER BY RAND() LIMIT 1;
//will return one random record  each time called;

SELECT column FROM table ORDER BY RAND() LIMIT 4;
//will return 4 random records each time called;
 
If I say:

SELECT column FROM table ORDER BY RAND() LIMIT 4;

and I only have 4 entries, is there any possibility that the same entry could be called twice, and another entry not be called at all?
 
bonkers said:
If I say:
SELECT column FROM table ORDER BY RAND() LIMIT 4;
and I only have 4 entries, is there any possibility that the same entry could be called twice, and another entry not be called at all?
what does random means :)
there may be some probability that one record may come next time,depends on the no of records
 
I found that when specifying a limit greater than 1, it may pick the same record(s) again. It's like picking names from a hat. It picks a name and puts it back, picks another name, puts it back again. I was under the impression that it would pick a name, take leave it out, and take another name, where the chances of picking the exact same paper/name would be 0.
 
hhon! that sounds interesting
what when you we have 1 quote and next time it comes
it will find zero.
eg:
random 1-10
4,9,6,3,8,1,5,3,8,2
means random
you can make your own function and memory to meet your demands :eek:
 
hrmm...I guess I really didn't mean random but rather scrambled. It's chill, it works now. :)
 
Back
Top