现在有文章表 article
和 文章回复表reply
article
id
title
user_id
create_time
reply
id
user_id
article_id
create_time
那么如何才能获取 用户最近10条文章 和 回复的文章 (加起来10条,而不是分别10条)
能否用一条语句完成,分开查询我会
解决了
(SELECT id,title,create_time,'article' as type FROM fb_articles WHERE user_id = 4)
UNION
(SELECT a.id,a.title,b.create_time,'reply' as type FROM fb_articles as a,fb_replys as b WHERE a.id = b.article_id AND b.user_id = 4)
ORDER BY
create_time
DESC
LIMIT 10
SELECT * FROM(SELECT user_id,title,create_time FROM article UNION ALL SELECT user_id,article_id,create_time FROM reply) ar WHERE ar.user_id=xxx ORDER BY create_time desc LIMIT 10