selecting date and previous dates
I have a database with an event date. I need to select the latest date and the varying amount dates previous to this. I came up with this but was
wondering if there would be a more efficient way to do this.
SELECT display_date FROM myDB WHERE display_date
BETWEEN SUBDATE((SELECT MAX(display_date) FROM myDB), INTERVAL 10 DAY)
AND (SELECT MAX(display_date) FROM myDB)
ORDER BY display_date
Example: Data in database
2004-05-27 00:00:00
2004-05-25 00:00:00
2004-05-26 00:00:00
2006-09-27 00:00:00
2006-09-25 00:00:00
2006-09-29 00:00:00
2006-09-28 00:00:00
2005-09-26 00:00:00
2005-09-25 00:00:00
2005-09-27 00:00:00
2005-09-28 00:00:00
Content Needed To Display and ordering
2006-09-25 00:00:00
2006-09-27 00:00:00
2006-09-28 00:00:00
2006-09-29 00:00:00
Many Thanks
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
|