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
Save operation failed
Connect to a Crosstab query in Access from Excel
How do I stop my accdr from running twice on the same computer
Format Number to Show without comma for thousands place
using Parameters.AddWithValue populated by QueryStringField
Exporting to pdf from crystal reports stopped working
Exchange 2010 After install when initialising it looks for the DC not the member server
SQL Server file proportions
Accessing Program files in Vista?
Can a property be added to each property in a collection class