mysql - sql语句问题?
大家讲道理
大家讲道理 2017-04-17 15:45:56
0
4
298

现在有文章表 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
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回覆(4)
洪涛

SELECT * FROM(SELECT user_id,title,create_time FROMarticle UNION ALL SELECT user_id,article_id,create_time FROM reply) ar WHERE ar.user_id=xxx ORDER BY create_time desc LIMIT 100%

迷茫

你是想要找最近回覆的10篇文章還是?

黄舟

union 一下依照日期排序取前10不就完了。

PHPzhong

雷雷

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!