We're tracking research data for different facilities in our DB (just SQLite at the moment while we develop the site on 5 different machines) the data enterers will enter information about an individual they're studying and periodically update the information while keeping the old info for making graphs and analyzing data later. At the moment, we do this by keeping a time stamp of when the data was entered, but we're struggling to figure out a query that will select only the individuals that correspond to the desired facility (foreign key), and that have the most recent timestamp as a dateTime field.
Right now we are getting all of the individuals for a facility from their table, sorting by the time, and then pulling all id's from the list generated, the first time we see them. But I know this will get slow and messy as entries increase. So, I was wondering if you guys had an idea for how to do this.
For the sake of this question you can assume:
Facility: pk, name, location
Individual: pk, ID, entryTime, FacilityFK
Also if you think this is a poor way of storing the data lmk that too, we have been trying to find ways to do it, and so far this is the only one we think will work, although they'll definitely need to have an IT team after we graduate because they will probably want to warehouse away a season's worth of data once it is over.