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条)

报告相同问题?