Hi All ;
The first select...union...select produces the correct result of about 15 records. The second select...union...select produces only one record (the most recent) when it should produces all the records as the first one does.
This has me stumped:
* This WORKS
select zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zPMH.tService), m.lcPatient ;
from zPMH, zICD9 ;
where zPMH.cICD9 = zICD9.cICD9 ;
and zPMH.cAccount = m.lcPatient ;
union ;
select ;
zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zItems.tfrom), m.lcPatient ;
from zItems, zDx, zICD9 ;
where zItems.cItem = zDx.cItem ;
and zDx.cICD9 = zICD9.cICD9 ;
and zItems.cPatient = m.lcPatient ;
group by 1 ;
order by 4 desc
* THIS FAILS!
* most recent occurance without duplication, in descending time order.
select ;
zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zItems.tfrom), m.lcPatient ;
from zItems, zDx, zICD9 ;
where zItems.cItem = zDx.cItem ;
and zDx.cICD9 = zICD9.cICD9 ;
and zItems.cPatient = m.lcPatient ;
union ;
select zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zPMH.tService), m.lcPatient ;
from zPMH, zICD9 ;
where zPMH.cICD9 = zICD9.cICD9 ;
and zPMH.cAccount = m.lcPatient ;
group by 1 ;
order by 4 desc
Any help is appreciated!
Thanks,
ajw
The first select...union...select produces the correct result of about 15 records. The second select...union...select produces only one record (the most recent) when it should produces all the records as the first one does.
This has me stumped:
* This WORKS
select zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zPMH.tService), m.lcPatient ;
from zPMH, zICD9 ;
where zPMH.cICD9 = zICD9.cICD9 ;
and zPMH.cAccount = m.lcPatient ;
union ;
select ;
zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zItems.tfrom), m.lcPatient ;
from zItems, zDx, zICD9 ;
where zItems.cItem = zDx.cItem ;
and zDx.cICD9 = zICD9.cICD9 ;
and zItems.cPatient = m.lcPatient ;
group by 1 ;
order by 4 desc
* THIS FAILS!
* most recent occurance without duplication, in descending time order.
select ;
zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zItems.tfrom), m.lcPatient ;
from zItems, zDx, zICD9 ;
where zItems.cItem = zDx.cItem ;
and zDx.cICD9 = zICD9.cICD9 ;
and zItems.cPatient = m.lcPatient ;
union ;
select zICD9.cCode, zICD9.cDesc, zICD9.cICD9, max(zPMH.tService), m.lcPatient ;
from zPMH, zICD9 ;
where zPMH.cICD9 = zICD9.cICD9 ;
and zPMH.cAccount = m.lcPatient ;
group by 1 ;
order by 4 desc
Any help is appreciated!
Thanks,
ajw