Hi,I'm trying to write this query and I can't seem to get it to work. I have a table that stores various attributes and maintains a DateCreated field to track the date.I would like to query out the most recent values for the various attributes. The goal is that later on I can re-create the mix of attributes for a specific date range.I was originally contemplating having a separate table to store the archive and one for the latest values.. does that approach make more sense? I read somewhere here that someone was using this approach successfully using triggers on the main table.I tried this:SELECT TID,AttributeID,AttrValueFROM Data dWHERE BID = 1 AND d.DateCreated = (SELECT Max(d2.DateCreated) FROM Data d2 WHERE d2.TID = d.TID AND d2.AttributeID = d.AttributeID)GROUP BY TestID,AttributeID,AttrValue,DateCreated
This seems to return all values still though.I also tried:SELECT TID,AttributeID,AttrValue,Max(DateCreated) AS MaxCreateFROM DataWHERE BID = 1GROUP BY TestID,AttributeID,AttrValue
I also tried using HAVING like this:SELECT TID,AttributeID,AttrValueFROM Data dWHERE BID = 1GROUP BY TestID,AttributeID,AttrValue,DateCreatedHAVING DateCreated = Max(DateCreated)
Thanks in advance for any guidance,Greg