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
Exchange 2007 EWS API change appointment
Excel 2007 VBE
Can I run the free MS Office Word viewer from command line to print a document?
Exactly what does Compact and Repair do?
What is a 'Database consistency check'?
How can I enable a template item accoding to query result ?
Modify a PARAM tag value within C#
Leading zero from number to Concatenated filed
Using If..Else in SQL Stored Procedure
Assign default value to array