Another UNION ALL query

From: Date: Thu, 29 Apr 2010 09:33:48 +0000
Subject: Another UNION ALL query
Groups: php.db 
Request: Send a blank email to php-db+get-47093@lists.php.net to get a copy of this message
I have a 'Highlights' heading on my home page. It is for links to content on the site ... like specific web pages I have designed the query below to select the two most popular and least popular pages used on the site to be the Highlights. (Each time a web page is accessed user_hits is increased by 1.) I would like to display a fifth one that is " ORDER BY RAND () LIMIT 1 " --- Only I don't know how to ensure it isn't one of the four that are being displayed already. Any suggestions? Ron SELECT highlights.reference, highlights.page_command, highlights.page_title FROM ( ( SELECT reference, page_command, page_title FROM user_pages WHERE include_in_highlights =1 ORDER BY user_hits DESC LIMIT 2 ) UNION ALL ( SELECT reference, page_command, page_title FROM user_pages WHERE include_in_highlights =1 ORDER BY user_hits ASC LIMIT 2 ) ) AS highlights ORDER BY highlights.page_title ASC

« previous php.db (#47093) next »