2009-11-24 59 views
0

我在用下面的查詢麻煩:MySQL查詢,沒有返回什麼,我期望

SELECT costingjobtimes.TimeStamp, costingdepartment.DeptDesc, costingemployee.Name, costingjobtimes.TimeElapsed FROM costingemployee INNER JOIN (costingdepartment INNER JOIN costingjobtimes ON costingdepartment.DeptID = costingjobtimes.DeptID) ON costingemployee.EmployeeID = costingjobtimes.EmployeeID; 

我希望它返回的costingjobtimes數據庫中的每一行但它只有返回4目前。

基本上我有3張桌子。 (costingjobtimes,costingdepartment,costingemployee)它們分別是:

mysql> DESCRIBE costingemployee 
    -> ; 
+------------+------------+------+-----+---------+-------+ 
| Field  | Type  | Null | Key | Default | Extra | 
+------------+------------+------+-----+---------+-------+ 
| EmployeeID | varchar(8) |  | PRI |   |  | 
| Name  | text  |  |  |   |  | 
+------------+------------+------+-----+---------+-------+ 
2 rows in set (0.00 sec) 

mysql> DESCRIBE costingdepartment 
    -> ; 
+----------+------------------+------+-----+---------+-------+ 
| Field | Type    | Null | Key | Default | Extra | 
+----------+------------------+------+-----+---------+-------+ 
| DeptID | int(10) unsigned |  | PRI | 0  |  | 
| DeptDesc | text    |  |  |   |  | 
+----------+------------------+------+-----+---------+-------+ 
2 rows in set (0.00 sec) 

mysql> DESCRIBE costingjobtimes 
    -> ; 
+-------------+------------------+------+-----+---------------------+----------- 
-----+ 
| Field  | Type    | Null | Key | Default    | Extra 
    | 
+-------------+------------------+------+-----+---------------------+----------- 
-----+ 
| id   | int(10) unsigned |  | PRI | NULL    | auto_incre 
ment | 
| EmployeeID | text    |  |  |      | 
    | 
| DeptID  | int(10) unsigned |  |  | 0     | 
    | 
| JobNumber | text    |  |  |      | 
    | 
| TimeElapsed | decimal(10,5) |  |  | 0.00000    | 
    | 
| TimeStamp | datetime   |  |  | 0000-00-00 00:00:00 | 
    | 
| JobRef  | text    |  |  |      | 
    | 
+-------------+------------------+------+-----+---------------------+----------- 
-----+ 
7 rows in set (0.00 sec) 

因此,所有的查詢應該做的是返回所有從costingjobtimes行,但放在員工的名字,而不是僱員和部門說明,而不是DEPTID。任何幫助將是巨大的..

由於提前,

回答

1

我不知道,如果一個內連接的您正在尋找真的什麼teishu。也許你應該嘗試正常的加入。

例如:

select e.Name, d.DeptDesc, j.JobNumber, j.TimeElapsed, j.TimeStamp, j.JobRef 
    from costingjobtimes as j 
    join costingdepartment as d on d.DeptID = j.DeptId 
    join costingemployee as e on e.EmployeeID = j.EmployeeID 

這應該給您提供從costingjobtimes表與僱員的姓名和部門的描述相結合的信息一個結果。

希望幫助。

+0

謝謝你們。這是更好的方式,但是我發現問題是costingemployee表中缺少一個索引,因此該索引的所有記錄都錯過了。 謝謝 – 2009-11-24 11:20:38