我正在构建一个类似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
答案 0 :(得分:1)
SELECT <columns>
FROM (
SELECT <columns>
FROM <friends criteria>
UNION
SELECT <columns>
FROM <current user criteria>
) x
order by msg_id desc
limit 10