I have an Access database that is used by 3 separate people offsite; this offsite location does not have a network link (nor can it).
I have three identical databases and thus three identical tables. Each user fills in information using the same Primary keys. For this ‘food evaluation’ example:
Item | Color | Timestamp
PERSON 1 (first database)
Carrot | Orange | 2012-12-21 13:00:00
Watermelon | Red | 2012-12-21 19:00:00 <--
Blueberry | Blue | 2012-12-21 17:00:00 <--
PERSON 2 (second database)
Carrot | Yellow | 2012-12-21 15:00:00 <--
Apple | Green | 2012-12-21 15:00:00 <--
PERSON 3 (third database)
Watermelon | Green | 2012-12-21 11:00:00
Apple | Red | 2012-12-21 14:00:00
Orange | Orange | 2012-12-21 15:00:00 <--
I need to output a table:
Blueberry | Blue | 2012-12-21 17:00:00
Watermelon | Red | 2012-12-21 19:00:00
Carrot | Yellow | 2012-12-21 15:00:00
Apple | Green | 2012-12-21 15:00:00
Orange | Orange | 2012-12-21 15:00:00
So, based on timestamp, I need to choose only ONE of the duplicates but also have all of the non-duplicates (Item is a Primary, Unique Key). I just can’t for the life of me get the SQL for this..
Using
SELECT Item, Color, MAX(timestamp)
FROM (SELECT ... FROM first
UNION SELECT ... FROM second
UNION SELECT ... FROM third)
GROUP BY Item, Color
But since it MUST group on Color to get a MAX function, it still creates index violations.
So.. how do I get this output?
You’re ignoring Color initially, just trying to find the latest Timestamp for each Item. So you must write a query that does only that, then you can JOIN it with the full table.