0

我正在建造一个类似 Facebook 的墙,并希望从当前用户和他们所有的朋友那里检索所有更新。

就目前而言,我只从用户的朋友那里获得更新。我如何也包含用户自己的更新?

SELECT  M.msg_id, 
    M.uid_fk, 
    M.message, 
    M.created,
    U.fname, 
    U.lname, 
    M.uploads 
FROM messages M INNER JOIN  users_friends F ON F.friendID = M.uid_fk

AND F.userID = " . $_SESSION['user_id'] . "
AND F.status = 2 
            INNER JOIN users U ON U.userID = F.friendID 

            order by M.msg_id desc limit 10
4

1 回答 1

1
SELECT <columns>
FROM (
    SELECT <columns>
    FROM <friends criteria>
    UNION
    SELECT <columns>
    FROM <current user criteria>
) x
order by msg_id desc
limit 10
于 2012-03-04T11:34:38.140 回答