dongzhun6952 2010-06-02 06:01
浏览 67
已采纳

PHP MySQL选择多个表

Is it posibble to select 3 tables at a time in 1 database?

Table 1: employee
              --> employee_id
              --> first_name
              --> last_name
              --> middle_name
              --> birthdate
              --> address
              --> gender
              --> image
              --> salary

Table 2: logs
              --> log_id
              --> full_name 
              --> employee_id
              --> date
              --> time
              --> status

Table 2: logout
              --> log_id
              --> full_name 
              --> employee_id
              --> date
              --> time
              --> status

I wanted to get the value of employee table where $id of selected. Then the $id also get the value of log.time, log.date, logout.time, and logout.date.

I already try using UNION but nothing happens.

  • 写回答

3条回答 默认 最新

  • douxu3315 2010-06-02 06:46
    关注

    Up to you to put it in your app, but the query looks like this. Dan's query will not return exactly what you said you're looking for.

    SELECT e.*, l.time, l.date, lo.time, lo.date 
      FROM employee e
      LEFT JOIN logs l 
        ON l.employee_id = e.employee_id
      LEFT JOIN logout lo
        ON lo.employee_id = e.employee_id
      WHERE e.employee_id = {your id here}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码