有一个表有四列:ID,FROM,TO,TIME
我想在FROM和TO值的基础上获取记录.
条件1:
FROM = [from value] AND TO = [to value]
第二个条件是:
FROM = TO AND TO = FROM
它应该返回最后20条记录.
解决方法:
你所追求的并不是很清楚.所以,这个猜测可能是错误的:
SELECT *
FROM Messages
WHERE ( fromUserID = @From AND toUserID = @To )
OR ( fromUserID = @To AND toUserID = @From )
ORDER BY TimeSent DESC
LIMIT 20 ;