Microsoft
Software
Hardware
Network
Question : Sql query
I have 2 tables.
tblContacts
ID
Name
LastMessageDate
tblMessages
ID
Message
ContactRef
RecvdDate
Each contact may have many messages. I just added the LastMessageDate field to the Contact table. I want to update it with the most recently recieved message for each contact, as recorded in the tblMessage table.
How can I write a query to do this?
Answer : Sql query
update tblContacts
set LastMessageDate = M.Lmd
from tblContacts C
inner join (select Id, max(LastMessageDate) as LMD from tblMessages group by Id) M
on c.Id = M.Id
Random Solutions
Reporting Services - Comparison Report
Small Business Server 2008 - TASK Scheduler Errors
After OCS F-E's IP was changed, Services would't start - SQL connection lost?
Can Access 2003 and 2007 coexist in peace on the same machine?
MS Access - References Lost When Distributing
MS Word conversion to Adobe
Adding a unique identifier to a field for export
WIndows Vista dont boot, blue screen
script will not removed mapped drive from user profiles
java based website not loading