如何连接两个有一个表的限制在 php mysql
How to join two tables having one will be limit in php mysql
我很难配置如何加入两个 table,第二个应该是限制。
下面是我的 table.
的样本
这是员工 table:
id EmpID Lastname Firstname Department
1 4 Joe Dylan Admin
2 5 Black Teddy Admin
这是出席人数table:
EmpID Date TimeIn TimeOut
4 2015-1-1 07:45 17:15
4 2015-1-2 08:15 15:00
4 2015-1-3 08:05 17:00
5 2015-1-1 08:00 16:00
5 2015-1-2 09:00 18:00
我想按 EmpID 合并两个 table,并且每页只显示一名员工。
这是我预期结果的示例:
EmpID: 4
Dept: Admin
Name: Joe, Dylan
Date TimeIn TimeOut
2015-1-1 07:45 17:15
2015-1-2 08:15 15:00
2015-1-3 08:05 17:00
你只需要加入并将where条件设置为:
$id=4;
$query="select employee.* ,attendance.* from (select * from employee where EmpID='".$id."') employee inner join attendance on employee.EmpID=attendance.EmpID";
尝试
SELECT * from employee
LEFT JOIN attendance on attendance.EmpID=employee.EmpID
这将是所有员工的所有考勤结果;但是,如果您希望每页有一条员工记录,则使用 PAgination 触发相同的查询;
SELECT * from employee
LEFT JOIN attendance on attendance.EmpID=employee.EmpID
WHERE employee.EmpID=per_page_emp_id
根据您的评论,您也需要日期要求...
SELECT * from employee
LEFT JOIN attendance on attendance.EmpID=employee.EmpID
WHERE employee.EmpID=per_page_emp_id AND (
attendance.date BETWEEN state 2015-1-1 AND 2015-1-1
我很难配置如何加入两个 table,第二个应该是限制。
下面是我的 table.
的样本这是员工 table:
id EmpID Lastname Firstname Department
1 4 Joe Dylan Admin
2 5 Black Teddy Admin
这是出席人数table:
EmpID Date TimeIn TimeOut
4 2015-1-1 07:45 17:15
4 2015-1-2 08:15 15:00
4 2015-1-3 08:05 17:00
5 2015-1-1 08:00 16:00
5 2015-1-2 09:00 18:00
我想按 EmpID 合并两个 table,并且每页只显示一名员工。
这是我预期结果的示例:
EmpID: 4
Dept: Admin
Name: Joe, Dylan
Date TimeIn TimeOut
2015-1-1 07:45 17:15
2015-1-2 08:15 15:00
2015-1-3 08:05 17:00
你只需要加入并将where条件设置为:
$id=4;
$query="select employee.* ,attendance.* from (select * from employee where EmpID='".$id."') employee inner join attendance on employee.EmpID=attendance.EmpID";
尝试
SELECT * from employee
LEFT JOIN attendance on attendance.EmpID=employee.EmpID
这将是所有员工的所有考勤结果;但是,如果您希望每页有一条员工记录,则使用 PAgination 触发相同的查询;
SELECT * from employee
LEFT JOIN attendance on attendance.EmpID=employee.EmpID
WHERE employee.EmpID=per_page_emp_id
根据您的评论,您也需要日期要求...
SELECT * from employee
LEFT JOIN attendance on attendance.EmpID=employee.EmpID
WHERE employee.EmpID=per_page_emp_id AND (
attendance.date BETWEEN state 2015-1-1 AND 2015-1-1