我需要清除SenderId
和RecipientId
。SELECT DISTINCT with two columns
所以我这样做:
SELECT DISTINCT M.SenderId, R.StudentId as RecipientId
FROM Message M (nolock) INNER JOIN Recipient R (nolock) ON M.Id=R.MessageId
GROUP BY M.SenderId, R.StudentId
HAVING StudentId=1 OR SenderId=1
而这个工作,但我还需要M.Text场在那里,但没有明显的。 所以我加了这个:
GROUP BY M.SenderId, R.StudentId, M.Text
但是这不起作用。
对于每个不同的M.Sender,R.StudentId是否可以有多个M.Text?如果是的话,你想选择哪一个? –
由于'(nolock)'关键字添加了'sql-server'标签 –
使用'distinct' **和**'group by'没有意义 –