View Full Version : Getting First/Last Values from a query


annemu
11-10-2008, 07:42 AM
I have a table of data that lists a patient's name, Medical record Number, Admission Date, Laboratory Haemoglobin Value, and the time the test was taken.
I want to limit the resuilts in the query to show only the patient's first Laboratory HB (haemoglobin) value, but I cannot get the query to work. It keeps outputting very strange results and I cannot figure out how to do it.
There are 1600 records within this table for approx. 192 patients. Any ideas?

Brianwarnock
11-10-2008, 08:13 AM
Anne there has been many discussions on the forum regarding the use of first and last but the experts conclusion is don't use them. I wont go into it now a search on First and Pat Hartman as user will point you at the info.

Now your problem, I think that you will need 3 queries
1 Groupby the first 2 fields of the current query and Min on Date this gives the earliest date
2 join this to the 2nd table and min on time to get earliest time
3 join this back to table on time + other fields as needed to then get the HB level. Run this query

Brian

annemu
11-10-2008, 10:42 PM
Cheers Brian,

I did what you suggested - it is a logical answer when you see the end result - just couldn't see the wood for the trees!

First time using this forum - delighted with the result!

Anne