0

I have these 3 tables with the following columns:

  1. employee: empId (PK), hireDate, jobTitle, department (FK), status (FK)
  2. status: statusId, statusDesc
  3. department: departmentId, deptName, supervisorId, deptHeadId

What I want to do is to display the following columns: hireDate, jobTitle, deptName, statusDesc

The problem that I'm encountering is that it does not display the statusDesc and deptName records.

Here's my code/sql query:

$empId = $_GET['empId'];

$result = mysql_query("SELECT e.empId, e.hireDate, e.jobTitle, d.deptName, s.statusDesc 
                        FROM employee e , department d, status s
                        WHERE e.department = d.departmentId AND e.status = s.statusId AND e.empId = $empId;");
4

2 回答 2

0

从您的查询中,如果员工有一个有效的部门和一个有效的状态 - 如果列是空白的,那么这是因为部门和状态表中的描述符字段是空的(deptName 和 statusDesc)。

于 2012-07-26T07:35:24.923 回答
0

尝试这个。

$empId = $_GET['empId'];

$result = mysql_query("SELECT e.empId, e.hireDate, e.jobTitle, d.deptName, s.statusDesc 
                        FROM employee e 
                        INNER Join department d on e.department = d.departmentId
                        INNER Join status s on e.status = s.statusId
                        WHERE e.empId = $empId;");
于 2012-07-26T07:50:16.953 回答