Re: [PHP] How to optimize select of random record in DB ?

2004-10-15 Thread Gareth Williams
What about in MySQL: SELECT personID from persons ORDER BY RAND(NOW()) LIMIT 1 If the table is large, then the following might be better: LOCK TABLES foo READ; SELECT FLOOR(RAND() * COUNT(*)) AS rand_row FROM foo; SELECT * FROM foo LIMIT $rand_row, 1; UNLOCK TABLES; There's a whole discussion on

[PHP] How to optimize select of random record in DB ?

2004-10-14 Thread -{ Rene Brehmer }-
I made this code to pick a random record from a changeable number of records in a given table. I'm just curious if any of the more awake coders out there can see a way to optimize this for better performance, since there's several other DB queries on the same page. $records =