Jake
Jake

Reputation: 1332

SQL query join issue

I have 3 tables that I am trying to combine into one with a query. One table"Main" has the primary key "AppID" and the other two tables "Net & Env" uses this key as a foreign key. What I am trying to do is make a join on the Main and Net AppID, for every appid that exist in Net and also for every Appid that exist in Env. My idea is that if I do a join on the Main and Net, then the only thing left is the AppIds in sync, but I want to also do the join from Main to Env. My query is:

SELECT Main.Name FROM ((Main INNER JOIN Net On Main.AppID=Net.AppID)INNER JOIN 
Env On Env.AppID=Main.AppID);

Do I need to have a subquery for the outer join. I know that the abover query is not giving me my desire results. Let me know if my question is unclear.

Upvotes: 0

Views: 64

Answers (1)

lweller
lweller

Reputation: 11317

Use a LEFT JOIN

SELECT m.Name FROM Main m LEFT JOIN Net n ON n.AppID=m.AppID LEFT JOIN Env e ON e.AppID=m.AppID;

Upvotes: 2

Related Questions