I need a query in DB2 where it has to select the maximum value in a string field. I have to select two other fields, in addition to the field that needs the max function performed on it. Here is a sample test that we have tried:
SELECT T1.EXPIRE_DATE,
T1.CUSTNUM,
T1.ZH4IN
FROM RTL.STG_MEDICAL_TABLE T1
WHERE T1.EXPIRE_DATE = SELECT MAX(T2.EXPIRE_DT)
FROM RTL.STG_MEDICAL_TABLE T2
SELECT T1.EXPIRE_DATE,
T1.CUSTNUM,
T1.ZH4IN
FROM RTL.STG_MEDICAL_TABLE T1
WHERE T1.EXPIRE_DATE = SELECT MAX(T2.EXPIRE_DT)
FROM RTL.STG_MEDICAL_TABLE T2
This worked Mike! Thanks a mil!
Jweir
--- If strength were all, tiger would not fear scorpion.
Don't you need the maximum expiry date for each CUSTNUM, ZH41N combination? This would need more conditions in the where clause, turning the query into a correlated subquery.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.