Inferno_str1ke
06-15-2009, 04:40 PM
I have a table that contains items with expiry dates on each item. I currently have a query that only shows unexpired items.
SELECT * FROM items WHERE expiry>$date
I need to change this so that it shows the most recent three expired items as well as the unexpired items. I could do it like this:
SELECT * FROM items WHERE expiry>$date;
SELECT * FROM items WHERE expiry=<$date ORDER BY expiry DESC LIMIT 3
But this relies on my using two queries. I could also just get the entire table, or estimate a date so that I'd have at least three expired items, and just filter out the rest with PHP. I'm just wondering if there's a more elegant single solution to this, that would allow one query to get me all useful records?
SELECT * FROM items WHERE expiry>$date
I need to change this so that it shows the most recent three expired items as well as the unexpired items. I could do it like this:
SELECT * FROM items WHERE expiry>$date;
SELECT * FROM items WHERE expiry=<$date ORDER BY expiry DESC LIMIT 3
But this relies on my using two queries. I could also just get the entire table, or estimate a date so that I'd have at least three expired items, and just filter out the rest with PHP. I'm just wondering if there's a more elegant single solution to this, that would allow one query to get me all useful records?