文章詳情頁
請教一條mysql的sql語句寫法;
瀏覽:152日期:2022-06-19 16:27:57
問題描述
現在是有兩張表;msg:針對單個用戶的普通消息通知;admin_msg:管理員發送給全部用戶的消息通知;
mysql> select * from msg;
idcontentdate1內容12016-08-03 11:56:542內容32016-08-05 11:57:062 rows in set
mysql> select * from admin_msg;
idcontentdate1內容22016-08-04 11:56:412內容42016-08-06 11:57:192 rows in set
我想要的效果是當執行 [此處是一段sql] order by date asc limit 0,2 的時候能獲取到meg中的 內容1 和 admin_msg中的 內容2 ;
那么問題來了;挖掘機;額不對;請問這段sql應該怎么寫?
先感謝各位大神的解答;
問題解答
回答1:select content, date from (select content, date from msg union all select content, date from admin_msg) subquery order by date asc limit 0, 2;回答2:
SELECT a.content as content1,b.content as content2 FROM msg AS a LEFT JOIN admin_msg AS b ON a.id = b.id WHERE a.id=1 ORDER BY a.date ASC LIMIT 2;
用到了左鏈接,獻丑了
相關文章:
排行榜
