dongroufan6846 2015-09-22 07:23
浏览 55
已采纳

如何连接两个表有一个将在php mysql中限制[关闭]

I am having a hard time configuring on how to join two tables, which the second one should be limit.

Below are the samples of my table.

This is employee table:

id EmpID Lastname Firstname Department
1  4     Joe      Dylan     Admin      
2  5     Black    Teddy     Admin

This is the attendance 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

I want to combine the two tables by EmpID and show only one employee per page.

This is a sample of my expected result:

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
  • 写回答

2条回答 默认 最新

  • dongsui4658 2015-09-22 07:34
    关注

    You just need to join and put where condition as:

    $id=4;
    $query="select employee.* ,attendance.* from (select * from employee where EmpID='".$id."') employee inner join attendance on employee.EmpID=attendance.EmpID";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了