2011-03-26 53 views
0

您好請幫我看看關於這個查詢,我從不同的表中獲取數據我面臨的問題是,在表中有類似的員工擁有的colum名稱,用戶也有名稱。查詢工作完美,但我wordering如何,我可以顯示此數據爲從內部連接查詢獲取數據

$data["employee.name"] 
$data["user.name"] 

這裏是查詢:

SELECT task.employee_id , task.user_id , task.service_id, user.name, 
     user.pic_path , employee.name ,employee.pic_path 
FROM task 
INNER JOIN employee ON employee.pno = task.employee_id 
INNER JOIN user ON user.pno = task.user_id 
INNER JOIN service ON service.service_id = task.service_id "; 

回答

4
SELECT user.name AS username, employee.name AS employeename 

你明白了吧。

+0

是的,謝謝,我知道了 – umar 2011-03-26 19:00:58

+0

如果你同意,接受爲正確答案;)乾杯。 – 2011-03-26 19:07:00

2

有兩個步驟:您需要定義列別名在SQL語句中的兩列的至少一個

  1. SELECT t.employee_id, 
         t.user_id, 
         t.service_id, 
         u.name AS user_name, 
         u.pic_path, 
         e.name AS employee_name, 
         e.pic_path 
        FROM TASK t 
        JOIN EMPLOYEE e ON e.pno = t.employee_id 
        JOIN USER u ON ur.pno = t.user_id 
        JOIN SERVICE s ON s.service_id = t.service_id 
    
  2. 然後,你需要更新PHP邏輯使用的列別名:

    $empname = $data["employee_name"]; 
    $username = $data["user_name"];