This question really belongs in the SQL forum (assuming you are using SQL?) or the appropriate DBMS forum since the exact SQL to do this will depend on your DBMS. Some have constructs like "TOP(N)" or "ROWNUM <= N" to get the first N rows from a query. The SQL I have shown below is less efficient but should work on any DBMS:
1) To get the latest N dates in the table:
Code:
select distinct start_date
from events e1
where N > (select count(distinct start_date)
from events e2
where e2.start_date > e1.start_date
);
NOTE: I am assuming start_date is a pure date with no time component. If it includes a time component you need to remove that - e.g. in Oracle you would use TRUNC(start_date).
2) To get all the data for those dates:
Code:
select *
from events
where event_date in
( select distinct start_date
from events e1
where N > (select count(distinct start_date)
from events e2
where e2.start_date > e1.start_date
)
);
Again, you'll need to ignore time components if they exist.
You only need query (2): I just showed query (1) to explain how the method works.