Let’s say I have a table that looks like this:
Id CheckboxId Selected DateCreated
1 1 1 1/1/2010
2 2 1 1/2/2010
3 1 0 1/3/2010
4 3 1 1/4/2010
5 3 0 1/5/2010
CheckboxId is a FK and the table is just a history of when the boxes are checked or unchecked.
What I want to get is the most recent record for each CheckboxId. In the case of my demo table I want rows 2, 3, and 5. How would you accomplish this? Also I’m sure this is as easy as a “where” at the beginning of the query but if it could also be modified to only get records before a specified date that would be fantastic.
I’m having trouble figuring out how I would write a query to do this in SQL and it’s making a link query impossible. I’m sure it has to be a selection from a sub query of distinct checkboxIds coupled with a group by or something but my SQL just isn’t that great.
Many thanks for your help.
Should be something like this:
Then you can do: