Renjith R
Renjith R

Reputation: 891

mysql query for upcoming event with start date and end date and show past event

I have a event table which start and end date stored like follows

 event_id   eventstartdate    eventenddate 
    1       2012-10-02         2012-10-20 
    2       2013-09-27         2013-10-27 
    6       2013-10-18         2013-11-18 
    8       2012-11-06         2012-11-23 
    9       2013-02-05         2013-02-12 
    10      2013-06-11         2013-06-13 

and i want to show the event order by the event start date from today..and get the past event based on the event start date in single query..

Expected result as follows

event_id   eventstartdate    eventenddate
      1      2013-09-27         2013-10-27 
      2      2013-10-18         2013-11-18
      3      2013-06-11         2013-06-13
      4      2013-02-05         2013-02-12
      5      2012-11-06         2012-11-23 
      6      2012-10-02         2012-10-20

Upvotes: 2

Views: 1682

Answers (3)

Mudasir Nazir
Mudasir Nazir

Reputation: 59

I think you should go with this Query

SELECT * FROM 
  table 
ORDER BY eventstartdate DESC

According to me it will give you all the events with start date order into desc. Mean today's event at top and minus one of current date and so on.

Upvotes: 0

Fabio
Fabio

Reputation: 23480

I think you can use CURDATE() to get actual data and then select all rows which are before the current data and then use ORDER BY to order in descending order from today

SELECT *
FROM table
WHERE eventstartdate < CURDATE()
ORDER BY eventstartdate DESC

Upvotes: 1

xQbert
xQbert

Reputation: 35323

Though I doubt this is what you're after. I need to see expected results to better understand the question.

SELECT Event_ID, EventStartDate, EventEndDate 
FROM Table
ORDER BY EventStartDate 

Upvotes: 0

Related Questions