Append this condition at the end of the query
........
........
........
WHERE client_unique_id LIKE ?
AND NOT EXISTS (
SELECT 1 FROM check_in CC
WHERE check_in.checkin_client_id = CC.checkin_client_id
AND CC.checkin_date < check_in.checkin_date
)
EDIT
It's hard to say looking only at the query and without knowing tables structures.
A general approach using NOT EXIST
works fine, look at this demo: http://sqlfiddle.com/#!2/9f99d/1
create table clients(
client_id int primary key
);
insert into clients values(1),(2),(3);
create table check_in(
check_in_id int primary key auto_increment,
checkin_client_id int,
checkin_date date
);
insert into check_in( checkin_client_id, checkin_date )
values
(1,'2014-02-01'),(1,'2014-02-03'),
(2,'2010-02-01'),(2,'2014-02-01'),(2,'2014-02-15'),
(3,'2010-12-01'),(2,'2014-01-21'),(2,'2014-02-10');
select *
from clients c
join check_in ci
on c.client_id = ci.checkin_client_id
where NOT EXISTS (
select 1
from check_in cc1
where ci.checkin_client_id = cc1.checkin_client_id
and ci.checkin_date < cc1.checkin_date
)
| CLIENT_ID | CHECK_IN_ID | CHECKIN_CLIENT_ID | CHECKIN_DATE |
|-----------|-------------|-------------------|---------------------------------|
| 1 | 2 | 1 | February, 03 2014 00:00:00+0000 |
| 2 | 5 | 2 | February, 15 2014 00:00:00+0000 |
| 3 | 8 | 3 | February, 10 2014 00:00:00+0000 |