Question

I am using iseries for DB2.I want to get the latest value for a column in Db2.? I tried using IDENTITY_VAL_LOCAL() but this needs an insert statement.In my case I don't perform any insertion. I want latest value inserted in a column in Db2, which is necessarily not recently inserted.

Was it helpful?

Solution

Do you have a timestamp field on your table? You could do something like:

SELECT id
FROM schema.table
ORDER BY tstamp DESC
FETCH FIRST ROW ONLY

If you don't, I'm not sure how you plan on defining "latest" (since you said in the other answer's comments that this is an alpha-numeric field that isn't necessarily in "order").

OTHER TIPS

Have you tried:

SELECT MAX(MYCOL) FROM MYTABLE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top