Hello All,
So here is a query i'm trying to run to get a randomized result from our db.
I've been looking for hours now on a solution and just don't seem to be finding what I need.
The difference is as such.
When I run the query without the order by rand() limit 1 I get a result in 0.0052
When I run the query with the above I get a result in 0.0517
It may seem like a decent result time but when the entire page i'm trying to load this query onto is loading in 0.03 that is adding quite a bit of extra latency (0.07 / 0.08).
Here is the query:
SELECT t3.idS, sum(t1.value - t1.price) as savings
FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.idC
INNER JOIN table3 t3 ON t3.idC = t1.id
WHERE t3.idS NOT IN (5653,21740)
GROUP BY t3.id
HAVING sum(t1.value - t1.price) > 100
ORDER BY RAND()
LIMIT 1
Any ideas what I can do to avoid the extra result time?
table1 = 598
table2 = 598
table3 = 10285
BTW if I remove table2 from query it takes almost double the time.. I have no idea why since it's not even being used in any of the values.
I would truely appreciate any help.
Thanks in advance,
Nick