Update Latest Record Of A Table With The Existing Record In Another Table

  1. update MAINTABLE set  
  2. MAINTABLE.DataId = B.DataId,   
  3. MAINTABLE.Source = B.Source   
  4. from   
  5. (SELECT U.mobile, U.dataid, U.Source, apptdate   
  6. FROM SECONDTABLE (NOLOCK) U,   
  7. (SELECT U.mobile, MAX(U.uploadeddate) uploadeddate, MAX(apptdate) apptdate   
  8. FROM SECONDTABLE (NOLOCK) U   
  9. INNER JOIN MAINTABLE (NOLOCK) L   
  10. ON U.MOBILE = L.MOBILE   
  11. GROUP BY U.mobile) A   
  12. WHERE U.MOBILE = A.MOBILE AND U.uploadeddate = A.uploadeddate) B   
  13. WHERE MAINTABLE.MOBILE = B.MOBILE   
  14. AND MAINTABLE.apptdate = B.apptdate