请教一条mysql的sql语句写法;
ringa_lee
ringa_lee 2017-04-17 15:19:25
0
2
625

现在是有两张表;
msg:针对单个用户的普通消息通知;
admin_msg:管理员发送给全部用户的消息通知;

mysql> select * from msg;

id content date
1 内容1 2016-08-03 11:56:54
2 内容3 2016-08-05 11:57:06

2 rows in set

mysql> select * from admin_msg;

id content date
1 内容2 2016-08-04 11:56:41
2 内容4 2016-08-06 11:57:19

2 rows in set

我想要的效果是当执行 [此处是一段sql] order by date asc limit 0,2 的时候能获取到meg中的 内容1 和 admin_msg中的 内容2 ;

那么问题来了;挖掘机;额不对;请问这段sql应该怎么写?

先感谢各位大神的解答;

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
Peter_Zhu
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;

用到了左链接,献丑了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!