I have 3 tables: Employees, Locations, and EmpLocation
- Employees stores employee data with Employee_ID as primary key,
- Locations stores location data with Location_ID.
- EmpLocation stores Employee_ID and Location_ID. Each Employee can have multiple locations.
I need to create an interactive grid that will display data for all employees, including those that do not have a location assigned to them. Then the user needs to have the ability to select a location for those employees that have it as null, and and also to add an additional location to any employee. I figured what I need is two select lists in an editable grid. So new row could be added by selecting an employee and corresponding location.
I used the following query:
SELECT el.Employee_ID, el.Location_ID
FROM EmpLocations el
Then I made each column a select list where the first one pulls data from Employees table:
SELECT Employee_FName, Employee_ID FROM Employees
and second - from Locations:
SELECT Location_Name, Location_ID FROM Locations
Everything looks good, but this way I only get employees who has at least one location assigned to them. I need to see all amployees and whether or not they have any locations assigned to them ( each employee can have more than one location assigned).
So I changed the source query for the grid to:
SELECT e.Employee_ID, el.Location_ID
FROM Employees e
LEFT JOIN EmpLocations el ON e.Employee_ID=el.Employee_ID
But in this case, will it be possible to make the grid updatable since there are two tables involved?