$uid='1602241320282666';
$sql="SELECT * from (
SELECT * FROM (
(SELECT userid as uid,stime FROM u_msg WHERE sender = '$uid')
UNION
(SELECT sender as uid,stime FROM u_msg WHERE userid = '$uid')
ORDER by stime DESC) as tmp GROUP BY tmp.uid ORDER BY tmp.stime DESC limit 2000
) as t LEFT JOIN talk_uinfo as u on t.uid = u.uid";
$iden=mysql_query($sql);
while($rsin=mysql_fetch_array($iden)){
echo $rsin['uid']." ".$rsin['stime']."<br>";
}
(SELECT userid as uid,stime FROM u_msg WHERE sender = '$uid')
UNION
(SELECT sender as uid,stime FROM u_msg WHERE userid = '$uid')
发送者和接收者字段刚好相对作为条件