update MAINTABLE set
MAINTABLE.DataId = B.DataId,
MAINTABLE.Source = B.Source
from
(SELECT U.mobile, U.dataid, U.Source, apptdate
FROM SECONDTABLE (NOLOCK) U,
(SELECT U.mobile, MAX(U.uploadeddate) uploadeddate, MAX(apptdate) apptdate
FROM SECONDTABLE (NOLOCK) U
INNER JOIN MAINTABLE (NOLOCK) L
ON U.MOBILE = L.MOBILE
GROUP BY U.mobile) A
WHERE U.MOBILE = A.MOBILE AND U.uploadeddate = A.uploadeddate) B
WHERE MAINTABLE.MOBILE = B.MOBILE
AND MAINTABLE.apptdate = B.apptdateThis code snippet is for to update latest record of a table with the existing record in another table.
