TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Update Latest Record Of A Table With The Existing Record In Another Table
Vandana
Aug 20
2016
Code
526
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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.apptdate
SQL Server
Update Latest Record