I have one table that holds my ressources:
Ressource | Ressource-ID
And a table that holds the associations
Ressource-ID | Employee-ID
How to select the ressources of an Employee that are available, i.e. not in the association table?
I’ve tried this, but it’s not working:
select r.ress, r.ress_id
FROM Ressource r
LEFT outer JOIN Ressource_Employee_Association a ON r.ress_id = a.ress_id
WHERE a.emp_id = 'ID00163efea66b' and a.ress_id IS NULL
Any ideas?
Thanks
Thomas
After writing my above comments, and looking at the proposed solutions: I think I’ve got some more understanding of what you are trying to do.
Assuming you have unlimited quantity of resources in your resources table, you want to select the un-assigned resources per employee (based on their non-existence for any specific employee in the resource association table).
In order to accomplish this (and get a comprehensive list of employees) you’ll need a 3rd table, in order to reference the complete list of employees. You’ll also need to
CROSS JOINall of the resources onto the list of employees (assuming every employee has access to every resource), then youLEFT JOIN(LEFT OUTER JOINwhatever) your association list onto the query where theresource_idandemployee_idmatch theresource_idin theresourcestable, and theemployee_idin theemployeestable (respectively). THEN you add your where clause that filters out all the records that assign an employee to a resource. This leaves you with the resources that are available to the employee, which they also do not have signed out. This is convoluted to say, so hopefully the query sheds more light:If you don’t have an
employeestable, you can accomplish the same by using the assigned resources table, but you will be limited to selecting employees who already have some resources allocated. You’ll need to add aGROUP BYquery because of the possible existence of multiple employee definitions in the association table. Here’s what that query would look like: