Look at the table (e.g TRClient)
| ID | clientid | sId | startdate | enddate | |----|----------|-----|--------------|--------------| | 1 | 10 | 1 | '2011-06-01' | '2012-05-31' | | 2 | 25 | 3 | '2011-06-01' | '2012-05-31' | | 3 | 10 | 1 | '2012-06-01' | '2013-05-31' |
I want clientid whose enddate is not greater than or equal to it’s previous record’s enddate
(relationship between two records can be determine by sId).
I have made the following query:
(here I am using loop for each client id in TRClient)
Select clientid from TRClient where clientId = 10 and sId = 1 and not (endDate >= '2012-05-31')
I want to check record for highest id for each client (If clientid and sId are same then it should check only for one record whose id is greater. e.g. in the given table if we are talking about clientid = 10 and sid = 1 we will get two rows(id = 1 and id = 3). Here I want to check enddate >= '2012-05-31' for id = 3)
This is what I wanted to do: