I have a database that will store events. Each event has different activities. The database is made as so (I know this is not the best database design, but I am working with what was given to me) :
eventID | date | eventname | activity
___________________________________________
0001 | 01/01/2012 | name1 | activty1
0002 | 01/01/2012 | name1 | activty2
0003 | 01/05/2012 | event2 | activty1
0004 | 01/05/2012 | event2 | activty2
0005 | 01/07/2012 | name1 | activty1
The same event can have multiple activities. The only way I can get the all records from an event (activities) is by the eventname column.
What I am trying to do is get the last 20 events with all it's activities. Therefore I cannot simply select 20 rows (using LIMIT
as this would not get me 20 events everytime as some events have 2 activities and others 10).
I cannot use SELECT DISTINCT eventname
because some events have same name, on different dates. What I would need is to have a distinct eventname only if the date is different.
I'm lost for ideas.
Thanks.