Multiple Join to the same field
-
Hi, i have the following code:
SELECT visit_investigations.*,
price_list_items.*,
employee.employee_short_name as created_by
FROM visit_investigations
INNER JOIN price_list_items ON price_list_items.item_id = visit_investigations.item_id
INNER JOIN employee ON visit_investigations.created_user = employee.employee_number
WHERE visit_investigation_id = param_visit_investigation_id;where created by is the employee created the record andit will never be blank. I want to add the field visit_investigations.result_by for the user who submited the result. this will be a number representing the employee.employee_number and it might be blank for records without result yet. How can I do this?
Technology News @ www.JassimRahma.com
-
Hi, i have the following code:
SELECT visit_investigations.*,
price_list_items.*,
employee.employee_short_name as created_by
FROM visit_investigations
INNER JOIN price_list_items ON price_list_items.item_id = visit_investigations.item_id
INNER JOIN employee ON visit_investigations.created_user = employee.employee_number
WHERE visit_investigation_id = param_visit_investigation_id;where created by is the employee created the record andit will never be blank. I want to add the field visit_investigations.result_by for the user who submited the result. this will be a number representing the employee.employee_number and it might be blank for records without result yet. How can I do this?
Technology News @ www.JassimRahma.com
I beleve you want to join to the employee table more than once. It would be something like: INNER JOIN employee e1 ON visit_investigations.created_user = e1.employee_number INNER JOIN employee e2 ON = e2.employee_number Hope that helps. :cool:
-
Hi, i have the following code:
SELECT visit_investigations.*,
price_list_items.*,
employee.employee_short_name as created_by
FROM visit_investigations
INNER JOIN price_list_items ON price_list_items.item_id = visit_investigations.item_id
INNER JOIN employee ON visit_investigations.created_user = employee.employee_number
WHERE visit_investigation_id = param_visit_investigation_id;where created by is the employee created the record andit will never be blank. I want to add the field visit_investigations.result_by for the user who submited the result. this will be a number representing the employee.employee_number and it might be blank for records without result yet. How can I do this?
Technology News @ www.JassimRahma.com
As David has suggested you need a 2nd join to the employee table but make it a LEFT join if there are missing records.
Never underestimate the power of human stupidity RAH