Hi all
having extreme problems with a query
the folowing query gives me the wrong date
SELECT p_timeline.oid as ptimoid, p_timeline.fk_oid as ptimfk_oid,
p_timeline.TXDATE, p_timeline.TXMOD, p_timeline.TXREAS,TXMOD.codetext as treatment,
TXSUPR.codetext as Place, p_timeline.TXSUPR,
p_timeline.TXSITE, site.codetext as Unit,
p_timeline.TXACC, p_timeline.TXANAT, p_timeline.TXCATH, p_timeline.TXPDFL, p_timeline.TXUNIT_NEW
FROM p_timeline
left join codes as site on site.proid = p_timeline.TXSITE
left join codes as TXSUPR on TXSUPR.proid = p_timeline.TXSUPR
left join codes as TXMOD on TXMOD.proid = p_timeline.TXMOD
where p_timeline.fk_oid = '10888'
group by p_timeline.fk_oid
order by p_timeline.TXDATE desc
it gives this
27525, 10888, 2010-03-10 00:00:00, 8320, , Transplant; Cadaver donor, , , 8200, St James's, , , , ,
if I change the query to show all data against the patient
SELECT p_timeline.oid as ptimoid, p_timeline.fk_oid as ptimfk_oid,
p_timeline.TXDATE, p_timeline.TXMOD, p_timeline.TXREAS,TXMOD.codetext as treatment,
TXSUPR.codetext as Place, p_timeline.TXSUPR,
p_timeline.TXSITE, site.codetext as Unit,
p_timeline.TXACC, p_timeline.TXANAT, p_timeline.TXCATH, p_timeline.TXPDFL, p_timeline.TXUNIT_NEW
FROM p_timeline
left join codes as site on site.proid = p_timeline.TXSITE
left join codes as TXSUPR on TXSUPR.proid = p_timeline.TXSUPR
left join codes as TXMOD on TXMOD.proid = p_timeline.TXMOD
where p_timeline.fk_oid = '10888'
-- group by p_timeline.fk_oid
order by p_timeline.TXDATE desc
I get four lines and the last date is 2011-01-06
'60692', '10888', '2011-01-06 03:00:00', '8432', NULL, 'York Low Clearance Patient', 'Hosp', '8091', '8217', 'Beeston', NULL, NULL, NULL, NULL, NULL
'27525', '10888', '2010-03-10 00:00:00', '8320', NULL, 'Transplant; Cadaver donor', NULL, NULL, '8200', 'St James''s', NULL, NULL, NULL, NULL, NULL
'27526', '10888', '2006-10-04 00:00:00', '8301',
NULL, 'Haemodialysis', 'Hosp', '8091', '8200', 'St James''s', NULL, NULL, NULL, NULL, NULL
'27527', '10888', '2006-01-28 00:00:00', '8301', NULL, 'Haemodialysis', 'Hosp', '8091', '8200', 'St James''s', NULL, NULL, NULL, NULL, NULL
Not sure why this is happening, cannot use p_timeline.oid as the data was inported incorrectly for the test db.
Your help would be most appreciated, if I change the following line
order by p_timeline.TXDATE desc limit 1
it works perfectly, but when I look at all the patient records, I only get the last record.
Thank you all for all your time
Ralph
having extreme problems with a query
the folowing query gives me the wrong date
SELECT p_timeline.oid as ptimoid, p_timeline.fk_oid as ptimfk_oid,
p_timeline.TXDATE, p_timeline.TXMOD, p_timeline.TXREAS,TXMOD.codetext as treatment,
TXSUPR.codetext as Place, p_timeline.TXSUPR,
p_timeline.TXSITE, site.codetext as Unit,
p_timeline.TXACC, p_timeline.TXANAT, p_timeline.TXCATH, p_timeline.TXPDFL, p_timeline.TXUNIT_NEW
FROM p_timeline
left join codes as site on site.proid = p_timeline.TXSITE
left join codes as TXSUPR on TXSUPR.proid = p_timeline.TXSUPR
left join codes as TXMOD on TXMOD.proid = p_timeline.TXMOD
where p_timeline.fk_oid = '10888'
group by p_timeline.fk_oid
order by p_timeline.TXDATE desc
it gives this
27525, 10888, 2010-03-10 00:00:00, 8320, , Transplant; Cadaver donor, , , 8200, St James's, , , , ,
if I change the query to show all data against the patient
SELECT p_timeline.oid as ptimoid, p_timeline.fk_oid as ptimfk_oid,
p_timeline.TXDATE, p_timeline.TXMOD, p_timeline.TXREAS,TXMOD.codetext as treatment,
TXSUPR.codetext as Place, p_timeline.TXSUPR,
p_timeline.TXSITE, site.codetext as Unit,
p_timeline.TXACC, p_timeline.TXANAT, p_timeline.TXCATH, p_timeline.TXPDFL, p_timeline.TXUNIT_NEW
FROM p_timeline
left join codes as site on site.proid = p_timeline.TXSITE
left join codes as TXSUPR on TXSUPR.proid = p_timeline.TXSUPR
left join codes as TXMOD on TXMOD.proid = p_timeline.TXMOD
where p_timeline.fk_oid = '10888'
-- group by p_timeline.fk_oid
order by p_timeline.TXDATE desc
I get four lines and the last date is 2011-01-06
'60692', '10888', '2011-01-06 03:00:00', '8432', NULL, 'York Low Clearance Patient', 'Hosp', '8091', '8217', 'Beeston', NULL, NULL, NULL, NULL, NULL
'27525', '10888', '2010-03-10 00:00:00', '8320', NULL, 'Transplant; Cadaver donor', NULL, NULL, '8200', 'St James''s', NULL, NULL, NULL, NULL, NULL
'27526', '10888', '2006-10-04 00:00:00', '8301',
NULL, 'Haemodialysis', 'Hosp', '8091', '8200', 'St James''s', NULL, NULL, NULL, NULL, NULL
'27527', '10888', '2006-01-28 00:00:00', '8301', NULL, 'Haemodialysis', 'Hosp', '8091', '8200', 'St James''s', NULL, NULL, NULL, NULL, NULL
Not sure why this is happening, cannot use p_timeline.oid as the data was inported incorrectly for the test db.
Your help would be most appreciated, if I change the following line
order by p_timeline.TXDATE desc limit 1
it works perfectly, but when I look at all the patient records, I only get the last record.
Thank you all for all your time
Ralph