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 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)