select ptn_id , study_date as st_date from study1 as a INNER JOIN
patient1 as b ON a.ptn_id_id = b.ptn_id_id
where abs(datediff(day,study_date,getdate()))=
(select min(abs(datediff(day,study_date,getdate()))) from study1 where ptn_id=a.ptn_id)
patient1 as b ON a.ptn_id_id = b.ptn_id_id
where abs(datediff(day,study_date,getdate()))=
(select min(abs(datediff(day,study_date,getdate()))) from study1 where ptn_id=a.ptn_id)
FROM study1 a INNER JOIN
patient1 b ON a.ptn_id_id = b.ptn_id_id INNER JOIN
series1 c ON a.study_uid_id = c.study_uid_id
where study_date=
(select max(study_date) from study1 where ptn_id=a.ptn_id)
FROM study1 a
INNER JOIN patient1 b ON a.ptn_id_id = b.ptn_id_id
INNER JOIN series1 c ON a.study_uid_id = b.study_uid_id
where not exists(select 1 from study1
where ptn_id_id=a.ptn_id_id
and study_date>a.study_date)
FROM study1 a INNER JOIN
patient1 b ON a.ptn_id_id = b.ptn_id_id INNER JOIN
series1 c ON a.study_uid_id = c.study_uid_id
where study_date=
(select max(study_date) from study1 where ptn_id=a.ptn_id)
SELECT *
FROM study1 a INNER JOIN
patient1 b ON a.ptn_id_id = b.ptn_id_id INNER JOIN
series1 c ON a.study_uid_id = c.study_uid_id
where study_date=
(select max(study_date) from study1 where ptn_id=b.ptn_id)