Subject Re: [ib-support] selecting max date
Author Robert F. Tulloch
Hi:

Never mind, I got it. Just a little slow. 13 seconds on table
with only 9000 records. Ugh.

SELECT DISTINCT ID, MGRID, CAST(CAST(ADRESS_TEN AS INTEGER) AS
CHAR(7)) AS ADRESS_TEN, STNAME_TEN, CITY_TEN, STATE_TEN,
SUBSTR(ZIP_TEN,1,5) AS ZIP_TEN, MAXDATE
FROM TENANTS T1
WHERE ADRESS_TEN >0 AND MAXDATE >= CURRENT_DATE - 1827 AND
MAXDATE = (SELECT MAX(T2.MAXDATE) FROM TENANTS T2
WHERE T1.ADRESS_TEN = T2.ADRESS_TEN AND
T1.STNAME_TEN = T2.STNAME_TEN AND
T1.CITY_TEN = T2.CITY_TEN AND
T1.STATE_TEN = T2.STATE_TEN)


Order By STATE_TEN Asc, CITY_TEN asc, STNAME_TEN Asc, ADRESS_TEN
Asc , MAXDATE ASC

Probably need an SP.

Thanks.

Best
regards