Kris Burford [EMAIL PROTECTED] wrote:
hi
wondering whether someone can set me straight on whether it's possible to
request a set of records from a single table with multiple conditions.
for instance, a story table, containing id, title, text, section and
published_date. what i would like is to retrieve is the 5 most recently
published stories from each section (currently there are nine sections).
so, do i have to do this in nine separate queries or can i do something like:
SELECT id, title, text, sectioned, published_date
FROM stories
WHERE (section = 'events' order by published_date desc limit 5) and
(section = 'features' order by published_date desc limit 5)
If I've got you right you need UNION:
(SELECT id, title, text, sectioned, published_date
FROM stories
WHERE section = 'events' ORDER BY published_date DESC LIMIT 5)
UNION
(SELECT id, title, text, sectioned, published_date
FROM stories
WHERE section = 'features' ORDER BY published_date DESC LIMIT 5);
http://www.mysql.com/doc/en/UNION.html
--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
__ ___ ___ __
/ |/ /_ __/ __/ __ \/ /Victoria Reznichenko
/ /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED]
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net
___/ www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]