开发者

fetching data from the inner join query

开发者 https://www.devze.com 2023-02-20 04:28 出处:网络
hello please help me out regarding this query ,I amfetching data from different tableThe problem i am facing is that in the table there are similar colum name like employeehave and user has also name

hello please help me out regarding this query ,I am fetching data from different table The problem i am facing is that in the table there are similar colum name like employee have and user has also name . The query work perfectly but i am wordering about how i can display this data as

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

here is the query:

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 ";


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

You get the point.


There are two steps:

  1. You need to define a column alias for at least one of the two columns in the SQL statement:

    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. Then you need to update the PHP logic to use the column aliases:

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

精彩评论

暂无评论...
验证码 换一张
取 消