title: Oracle Single-row subquery returns more than one row error
body: <p>I have a scenario. Can this be done using one query ?</p>
  
  <ul>
  <li><p>Table Company : Single Company information with CPK as primary key and one Manager,Lead,HR attached to it</p></li>
  <li><p>Table Employees : For every Company there are Employees (1 or more can be up to 500) with unique empID and Manager,Lead,HR attached to it</p></li>
  <li><p>Table Employees Information (for using Web application) : he is assigned with 1 or more Manager,Lead,HR (or can be ALL,ALL,ALL which means he can see everything)</p></li>
  </ul>
  
  <p>So:</p>
  
  <pre><code>Company
  --------
  CPK (PK)
  Manager
  Lead
  HR
  
  Employees 
  --------
  empID (PK)
  CPK (FK)
  Manager
  Lead
  HR
  
  EmployeesInfo
  -------------
  USER_ID (FK)
  Manager
  Lead
  HR
  </code></pre>
  
  <p>Web --> When a user login he should get all company information.If he has access to that company or any employee within that company then that row is enabled else its greyed out(disable) if its "All" then he can edit every record</p>
  
  <p>For Example: 
  User1 is assigned to Manager1, Lead1 and HR1.<br>
  Then he can edit all records from Company where Manager = Manager1, Lead = Lead1 and HR = HR1.<br>
  Also records in Company which has employees with Company.CPK = Employee.CPK and Employee.Manager = Manager1 and Employee.Lead = Lead1 and Employee.HR = HR1</p>
  
  <p>My query till now But</p>
  
  <pre><code>select t2.MANAGER from Employees t2 where t2.CPK  = t1.CPK
  </code></pre>
  
  <p>returns Multiple record which is expected what should i do ???</p>
  
  <pre><code>SELECT  t1.*,
        --All condition
        CASE WHEN (SELECT MANAGER FROM EmployeesInfo WHERE USER_ID=44) = 'All' then 1
             ELSE(
                  --Check for Company
                  CASE 
                  WHEN t1.MANAGER  in (SELECT MANAGER FROM EmployeesInfo WHERE USER_ID=44) then 1
                  WHEN t1.LEAD in (SELECT LEAD FROM EmployeesInfo WHERE USER_ID=44) then 1
                  WHEN t1.HR  in (SELECT HR FROM EmployeesInfo WHERE USER_ID=44) then 1
             ELSE(
                  --Check Employee M,L,HR for that Company 
                  CASE
                  WHEN (SELECT t2.MANAGER FROM Employees t2 WHERE t2.CPK  = t1.CPK) in 
                         (SELECT MANAGER FROM EmployeesInfo WHERE USER_ID=44) then 1
                  WHEN (SELECT t2.LEAD FROM Employees t2 WHERE t2.CPK = t1.CPK ) in 
                         (SELECT LEAD FROM EmployeesInfo WHERE USER_ID=44) then 1
                  WHEN (SELECT t2.HR FROM Employees t2 WHERE t2.CPK  = t1.CPK  ) in 
                         (SELECT HR FROM EmployeesInfo WHERE USER_ID=44) then 1
                  ELSE 0 END
                  )
             END
             )
        END AS Grey_Out 
  FROM Company t1 
  WHERE  t1.CPK  ='1234'
  </code></pre>
  
  <p>Finally I should get all Company with grey_out field as (1 or 0) , then I will use the Grey_Out field for finding whether it should be made editable.</p>