I am trying to run a query to do the following:
return all the most recent records in a table between a given date range.
I am currently using this query
SELECT id FROM schedule WHERE eventdate BETWEEN '2014-09-01' AND '2014-09-07'
Which returns records 1,2,3,4,5 from the schedule table shown below
schedule table.
+ ---- + ------------ + ------------- + ----------------- + ------------ + ---------- +
| id | eventdate | resource_id | text | added_on | added_by |
+ ---- + ------------ + ------------- + ----------------- + ------------ + ---------- +
| 1 | 2014-09-05 | 1 | Some old text | 2014-08-01 | Sam |
| 2 | 2014-09-05 | 1 | Some newer text | 2014-09-01 | Jordan |
| 3 | 2014-09-06 | 1 | another day | 2014-09-03 | Jordan |
| 4 | 2014-09-05 | 1 | Most recent | 2014-09-10 | Jordan |
| 5 | 2014-09-07 | 2 | Other resource | 2014-09-09 | Sam |
+ ---- + ------------ + ------------- + ----------------- + ------------ + ---------- +
I am trying to return only unique records in the specified date range, where the unique records to be returned are those with the highest date stamp in the column added_on.
In the above example, I would like only 3,4,5 records to be returned. Entries 1 and 2 were replaced by entry 4.
** Please note: the column added_onhas a timestamp of the date of the date (yyyy-mm-dd HH: mm: ss) and is left for clarity **
, , , , - eventdate, resource_id and added_on
, , _