I have listed duplicates using the following:
select s.MessageId, t.*
from Message s
join (
select ToUserId, FromUserId, count(*) as qty
from Message
group by ToUserId, FromUserId
having count(*) > 1
) t on s.ToUserId = t.ToUserId and s.FromUserId = t.FromUserId
Now, how do I delete all but one of the Messages (I'm trying to remove duplicates so I can apply a unique index on FromUserId and ToUserId
).