Jump to content

Order By Usage


ThePsion5

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...