I'm trying to sort a population of animals from the table [ALL WEIGHTS] by those that are alive (from the table MainDeaths, field [STATUS: DEAD OR ALIVE], which is a list box with the options either "DEAD" or "ALIVE"). I then want to display them by last date they were weighed ([ALL WEIGHTS].[DATE OF WEIGHT]). I am doing this so I can set up a warning that tells me if a (live) animal has not been weighed in the last 14 days. I have tried this using Unique Values and Unique Records, and I've also tried making a separate "Live Animals" query and using this instead of coming straight from the MainDeaths table. I either get one of four results; 1. I get about 62000 results (there are only about 300 animals in the population). 2. I get each animal displayed twice, displayed as both "dead" and "alive". 3. I get the result that every animal in the population is "alive", which is not true. 4. The date of last weight is displayed as 26/11/2013 for every animal (this is the last time the last animal was weighed). This is the SQL I'm using - this particular code gives me the correct number of animals and the correct dates for when each animal was last weighed, but incorrectly tells me that every animal is "alive".
Code:
SELECT DISTINCT Last([ALL WEIGHTS].[DATE OF WEIGHT]) AS LastDate, [ALL WEIGHTS].[ANIMAL ID], MainDeaths.[STATUS: DEAD OR ALIVE]
FROM [ALL WEIGHTS], MainDeaths
GROUP BY [ALL WEIGHTS].[ANIMAL ID], MainDeaths.[STATUS: DEAD OR ALIVE]
HAVING (((MainDeaths.[STATUS: DEAD OR ALIVE])="ALIVE"));
.
Thanks all!
Adam