I posted this a month or so ago, and was helped a little, but I am now
back.
Currently I use select x, y, z from images where (condition) order by
rand() limit 1;
As most know, it is slow, depending on the record set, and what I
compare it to, it can be from one order of magnitude slower, to several.
I have cobbled together a solution, but it on occasion, returns an
empty result set, which is causing me grief. I should mention, there
are holes in my id column, and I am needing to select a set based on a
condition.
The below sql I do not fully understand either, if someone could step
me through it, I would certainly appreciate it, though my main goal is
to figure out why I get an empty set on occasion.
$sql = "
SELECT storage_path, image_md5, t.id
FROM images AS t
JOIN
(SELECT CEIL(MAX(id)*RAND()) AS id FROM images) AS x ON (t.id >=
x.id)
AND (t.approved = 1) AND (t.ip_address != '$exclude_ip')
LIMIT 1";
* I could almost live with the slow speed of an order by rand() but I
find it has a less than even distribution. While it indeed may be
very random, I am looking for a pretty flat response in distribution
of returned records over time.
--
Scott
[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]