这4个字段相互关联
我希望它输出为:
在我的查询中:
SELECT users.firstname, users.lastname, users.screenname, posts.post_id, posts.user_id,
posts.post, posts.upload_name, posts.post_type,
DATE_FORMAT(posts.date_posted, '%M %d, %Y %r') AS date,
COUNT(NULLIF(feeds.user_id, ?)) AS everybody, SUM(feeds.user_id = ?) AS you,
GROUP_CONCAT(CASE WHEN NOT likes.user_id = ? THEN
CONCAT_WS(' ', likes.firstname, likes.lastname)
END
) as names
FROM website.users users
INNER JOIN website.posts posts ON (users.user_id = posts.user_id)
LEFT JOIN website.feeds feeds ON (posts.post_id = feeds.post_id)
LEFT JOIN website.users likes ON (feeds.user_id = likes.user_id)
GROUP BY posts.pid
ORDER BY posts.pid DESC
现在,我有一个问题应该加入friends表的哪一部分,我想显示来自friend_id或user_id的所有帖子以及来自当前登录的用户的帖子。如果朋友表上没有匹配的朋友,那么只需输出用户的所有帖子。请各位,我需要你的帮助。
Friends.friend_id = 当前用户的好友
Friends.user_id = 用户的当前好友
因此,friends.friend_id = posts.user_id 或 friends.user_id = posts.user_id
如果我的朋友表无法理解,请帮我更改它以使其更好。