I have a table with 10 userids and passwords, I want to be able to randomly select only one row (one userid and password) from this table.
Can someone please help me?
I thank-you all in advance.
Gil
SELECT field1,field2,field3 FROM tablename ORDER BY RAND() LIMIT 0,1
Thank-you very much Danny for your help. That was exactly what I was looking for.
Once again, Thank-you
Or you could save MYSQL the work, and just generate the random number beforehand, and select that specific row.... but that is only if you use like a rowid or something of the sort...
NiXXed you'd most likely also need to know the entire set to randomly select from. What if I DELETE a row in the middle and I randomly SELECT that one? Obviously it will be blank, so I'll have to choose another random number. By the time your done, you may have done more SELECTs than where necessary instead of just a guaranteed 1 time with the SELECT ... ORDER BY RAND() LIMIT 0,1 clause.
Originally posted by NiXXeD Or you could save MYSQL the work, and just generate the random number beforehand, and select that specific row.... but that is only if you use like a rowid or something of the sort...
I'm pretty sure MySQL could do that faster than PHP actually, certainly not significantly slower.