Discussion Locked

logic problem

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

while going through a resultset, I get a bunch of records with many fields including date objects. I would like to display only the record with the latest date ? I'm really having trouble coding this.
Thank you

5 replies

by nise_k

Hi,

There are two methods :
1. Optimise the query itself, to get the record only with the max Date.
e.g SELECT * FROM TABLE WHERE ENTRY_DATE = (SELECT MAX(ENTRY_DATE) FROM TABLE)

2. Make a Function which compares two Dates and returns 1, 0 or -1, for First Date greater, First and Second Date are Same or First Date lesser, correspondingly .
e.g. int compareDate(date1, date2)

Then store the Dates you fetch from the ResultSet and compare the Current Date with the last Max Date read. If new date is greater, then store this date as the Max Date, keep comparing like this. Then you can find the appropriate record.

Bye.
Nise

This discussion is closed to new replies.