到目前为止我得到了这个
select user_id,topic_id
from
( select u.user_id, t.topic_id from `user` u inner join `topic` t on t.topic_by =u.user_id
union
select u.user_id, c.comment_topic from `user` u inner join `comment` c on c.comment_by=u.user_id
union
select u.user_id,th.thanks_by from `user` u inner join `thanks` th on th.thanks_by=u.user_id
)x
where x.user_id=33
但结果只有user_id和topic_id我想知道关于该主题的用户操作示例用户对主题A的评论,用户喜欢主题B,用户发布主题C 并按时间排序。
答案 0 :(得分:3)
试试这个......
SELECT u.user_id, t.topic_id, c.comment_topic, th.thanks_by
from user u
LEFT JOIN topic t ON t.topic_by =u.user_id
LEFT JOIN `comment` c on c.comment_by=u.user_id
LEFT JOIN `thanks` th on th.thanks_by=u.user_id
WHERE u.user_id = 33
GROUP BY u.user_id, t.topic_id, c.comment_topic, th.thanks_by