question

Vaz avatar image
Vaz asked

Sql Statement multiple tables

Three tables Employee, Manager, User_Account

Employee contains Employee_ID and User_Account_ID, Manager contains Employee_ID and Manager_ID, User_Account contains User_Account_ID and Password,

Results: Employee_ID, Manager_ID, User_Account_ID(For Employee), Password (For Employee), User_Account_ID(For Manager), Password (For Manager)

Whats the best way to achieve the results above?

selectjoinssub-query
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
malpashaa avatar image
malpashaa answered

Try this:

            
SELECT E.Employee_ID,            
       ME.Employee_ID AS Manager_ID,            
       E.User_Account_ID AS Employee_User_Account_ID,            
       (SELECT UA.Password            
          FROM User_Account AS UA             
         WHERE UA.User_Account_ID = E.User_Account_ID) AS Employee_Password,            
       ME.User_Account_ID AS Manager_User_Account_ID,            
       (SELECT UA.Password            
          FROM User_Account AS UA             
         WHERE UA.User_Account_ID = ME.User_Account_ID) AS Manager_Password            
  FROM Manager AS M            
       INNER JOIN            
       Employee AS ME            
       ON ME.Employee_ID = M.Manager_ID            
       RIGHT OUTER JOIN            
       Employee AS E            
       ON E.Employee_ID = M.Employee_ID;            
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.