Quote:
|
Originally Posted by r937
try this --
Code:
select distinct
d.ID
, d.Description
from employee as e1
inner
join employee as e2
on e2.ParentCompanyID = e1.ParentCompanyID
inner
join document
on d.EmployeeID in (e1.EmployeeID
,e2.EmployeeID)
and d.SharingID = 1
where e1.EmployeeID = $eid
|
ParentCompanyID column resides in the company table. This is a unique HeadOffice (single-level hierarchical data) for all the branches for simplicity. Company table is linked to the employee table but the above statement does not refer to the company table:
Company => ID, ParentCompanyID
Employee => ID, CompanyID
Document => ID, EmployeeID, SharingID
Sharing => ID, Description (data: 0 - Private, 1 - Public)
Here are the requirements:
Include all the documents of the current employee ($eid) - public/private.
Include only the shareable (public) documents of the employees of the same branch of $eid.
Include only the shareable (public) documents of the employees of the other branches of the company.
Thanks for your time...