x

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?

more ▼

asked May 12, 2010 at 05:48 AM in Default

avatar image

Vaz
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

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;            

more ▼

answered May 12, 2010 at 08:49 PM

avatar image

malpashaa
404 1 2 5

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x148
x146
x49

asked: May 12, 2010 at 05:48 AM

Seen: 936 times

Last Updated: May 12, 2010 at 05:48 AM

Copyright 2016 Redgate Software. Privacy Policy