glthornton
Programmer
Hi, I'm working on a SQL 2000 server and I'm trying to write a query that will return the latest instance of a patient's medication allergies. But my current query is only designed to pull all instances. Here is what my current SQL code looks like:
The results back look like this:
As you can see I have 2 drugs that are documented more than 1 time. I'd like to see if a query can be written to just provide me with the latest instance for each drug. So I would like to see the results as:
Is there a simplistic way of accomplishing this query? Any and all assistance would greatly be appreciated.
Thank you,
Glenn
Code:
SELECT DISTINCT ckt.name, prov.displayname, ckd.created
FROM ((Checkdata ckd INNER JOIN Checkmark ckm ON ckd.CID = ckm.CID) INNER JOIN checktext ckt ON ckd.DataID = ckt.DataID) INNER JOIN Providers prov ON ckd.DRID = prov.DRID
WHERE (ckt.name Is Not Null) AND (ckm.Name Like '%medication allergies%') AND (ckd.PatID= '35000')
The results back look like this:
Code:
Biaxin Nurse #1 2008-02-13 09:00:34.783
Biaxin Nurse #2 2007-10-05 12:38.47.860
Biaxin Nurse #2 2006-10-26 13:05.05.297
Advil Nurse #2 2008-01-10 11:12:15.820
Advil Nurse #1 2007-10-05 12:30.21.031
As you can see I have 2 drugs that are documented more than 1 time. I'd like to see if a query can be written to just provide me with the latest instance for each drug. So I would like to see the results as:
Code:
Biaxin Nurse #1 2008-02-13 09:00:34.783
Advil Nurse #2 2008-01-10 11:12:15.820
Is there a simplistic way of accomplishing this query? Any and all assistance would greatly be appreciated.
Thank you,
Glenn