我试图运行一个mysql连接查询从3个表中获取数据。 表1:用户 表2:Outtiming 表3:启动
我希望从具有相同日期的时间表和提升表中显示相同的日期数据。
例如:2017-09-13 = 2017-09-13
但是我没有得到相同日期的数据。
$query = "SELECT ur.username, ur.user_department, it.*, ot.*
FROM users ur
INNER JOIN intiming it ON ur.staff_id=it.staff_id
INNER JOIN outtiming ot ON ur.staff_id=ot.staff_id
WHERE it.staff_id=".$employee."
AND it.date >= '$startDate' AND ot.date <= '$endDate'";
结果
答案 0 :(得分:0)
在WHERE语句中添加一个添加条件以检查匹配日期:it.date = ot.date
。完整查询:
$query = "SELECT ur.username, ur.user_department, it.*, ot.*
FROM users ur
INNER JOIN intiming it ON ur.staff_id=it.staff_id
INNER JOIN outtiming ot ON ur.staff_id=ot.staff_id
WHERE it.staff_id=".$employee."
AND it.date >= '$startDate' AND ot.date <= '$endDate'
AND it.date = ot.date ";