SELECT plan.*, min(trkg.curwipprice_online) AS curwipprice_online, trkg.addr
FROM trkg
RIGHT OUTER JOIN plan
ON plan.cliorder = trkg.cliorder
WHERE (TIMESTAMP(NOW()) BETWEEN TIMESTAMP(plan.begin) AND TIMESTAMP(plan.end) )
GROUP BY plan.item_name DESC
All I changed was GROUP BY… to ORDER BY RAND().
SELECT plan.*, min(trkg.curwipprice_online) AS curwipprice_online, trkg.addr
FROM trkg
RIGHT OUTER JOIN plan
ON plan.cliorder = trkg.cliorder
WHERE (TIMESTAMP(NOW()) BETWEEN TIMESTAMP(plan.begin) AND TIMESTAMP(plan.end) )
ORDER BY RAND()
duh duh duh duhhhhhhh. Thanks again as usual. I value your help very much.
I was proceeding from a memory that I couldn’t combine a GROUP BY and an ORDER BY as in
SELECT plan.*, min(trkg.curwipprice_online) AS curwipprice_online, trkg.addr
FROM trkg
RIGHT OUTER JOIN plan
ON plan.cliorder = trkg.cliorder
WHERE (TIMESTAMP(NOW()) BETWEEN TIMESTAMP(plan.begin) AND TIMESTAMP(plan.end) )
GROUP BY plan.item_name DESC
ORDER BY RAND()
Though, this appears that it produces the result I need.
Instead of using the ORDER BY RAND() , drop that bit and once you’ve got the result set into an array using whatever server-side language you’re using, it’ll be quicker. There is a thread somewhere (either in the PHP or the Database forum), I can’t remember the thread title but the efficiency of different methods for getting a random result set were tested and compared including how well they scaled up (execution time) as the result sets got bigger.