我得到的是
表格:
employee {id, name, phone, dep_link[fk]}
department {id, name}
groups {id, name}
employees_groups {id, emp_id_link[fk] ,group_id_link[fk]}
departments_groups {id, dep_id_link[fk], group_id_link[fk]}
逻辑:
{dep_link[fk]}
)我对表和关系做了什么?我有两个部门(IT,Archives),他们是该组的一部分(All)。将关系添加到departments_groups表后,如何检索这些部门的员工?
答案 0 :(得分:0)
例如,我有两个部门(IT,档案馆),他们是其中的一部分 将关系添加到departments_groups之后的group(All) 表如何检索这些部门的员工?
SELECT * FROM employee WHERE employee.dep_link
IN (SELECT dep_id_link FROM departments_group INNER JOIN groups
ON groups.id = group_id_link AND groups.name = 'All')
答案 1 :(得分:0)
我认为这更符合您的需求:
select e.id
,e.name
,e.phone
from employee e
,group g
,employee_groups eg
where e.id = eg.emp_id_link
and g.id = eg.group_id_link
and g.name = "all"
希望它有所帮助。 :)