ThePsion5 Posted February 25, 2006 Share Posted February 25, 2006 Hi,I'm have a web interface that displays "events" if they're start date and end date aren't beyond the current date, so i created a query to do that: SELECT event, headline FROM events WHERE DATEDIFF(CURRENT_DATE(), startDate) >= 0 AND DATEDIFF(endDate, CURRENT_DATE) >= 0 This script seems to work fine. However, I want to group these so that the one that expires soonest is at the top, and I thought that this code would do the trick: SELECT event, headline FROM events WHERE DATEDIFF(CURRENT_DATE(), startDate) >= 0 AND DATEDIFF(endDate, CURRENT_DATE) >= 0 GROUP BY (DATEDIFF(CURRENT_DATE(), startDate) DESC) but this gives me an SQL syntax error...what am i doing wrong? Link to comment Share on other sites More sharing options...
Pollux Posted February 27, 2006 Share Posted February 27, 2006 It sounds like you should be using ORDER BY rather than GROUP BY.By "the one that expires soonest first", I assume you mean the enddate that comes first? Therefore you'd want ORDER BY enddate. Link to comment Share on other sites More sharing options...
ThePsion5 Posted February 27, 2006 Author Share Posted February 27, 2006 Thanks, that seems to have worked Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now