General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Thanks for that Fabio.
i had to make small changes to run suggested query work. it runs fine but missing out some patients.
i know for 2 sure that i've 2 records that matches my criteria but this query returns only first one it finds. looks like "Last_result_date" always same in join!!
SELECT ;
master.NHI as Patient_Numbers_UR_Number,;
PADR(mastername ('sk', master.name, master.surname, master.firstnames, master.knownname),60) as Name_Address_Full_Known_Name,;
Last_result_date,;
rp1.value AS Result,rp1.pkey;
from master;
inner join res_pat as rp1 on rp1.master = master.pkey;
inner join (select master,MAX(resdate) Last_result_date from res_pat group by master) last;
on rp1.master = last.master ;
where rp1.resdate=last.Last_result_date AND rp1.pkey in ; && simplified this part: put the IN into the inner join
(select res_pat1.pkey FROM master,;
test_pat test_pat1, test test2, res_pat res_pat1; && put join here !!!!!
WHERE ;
(UPPER (PADR(test2.Name,30)) LIKE "BMI");
AND year (res_pat1.Resdate) = 2005 AND;
(master.status = 0 AND test_pat1.MASTER = master.PKEY AND test_pat1.status < 2;
AND test_pat1.TEST = test2.PKEY AND test2.status < 2;
AND res_pat1.TEST_PAT = test_pat1.PKEY AND res_pat1.status < 2))
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only