Mysql 的多表关联查询
2017-05-12 本文已影响0人
Super_圣代
最近在和老师合作给一家公司做一个项目,我一个人就要完成服务端接口 和 Android APP ,简直一个头四个大!
服务端使用的PHP 的一个叫PhalApi的轻量级接口框架,还是挺不错的 , 数据库则使用了Mysql , 这个项目等结束后我会好好总结下,因为还是学到了不少东西。
这次的问题,一个mysql的多表查询语句,没什么难度,主要是我总是记不得(吐血ing。。。)。
首先是数据库结构 (一个签到功能的部分)
用户信息表:

签到表:

签到类型表:

我需要得到的是数据用户姓名,签到日期,签到时间,签到类型名。查询语句如下
SELECT
b.name,
a.sign_date,
a.sign_time,
c.type_name
FROM
signin_table AS a
JOIN user_table AS b ON (a.user_id=b.id)
JOIN signin_type AS c ON (a.sign_type=c.id)
WHERE
(a.user_id=18)
可以得到结果

OK,完成
继续写接口。。。