Avatar of haboltn
haboltn
Flag for United States of America asked on

SQL Query - exclude with Join?

I have two tables, one has user information the other has users who are on a team. The result set from the query below gives me the information I want, except for it includes the people from the user table that are already on teams (and displays them multiple times).

We know a user is on a team if they have an entry in the team_member table. So how can I exclude the userIDs from the result set that are already in the team_member table? I need to do this in one query. I am working from SQL Server.

Thank you very much!
SELECT     dbo.tbl_user.display_name, dbo.tbl_user.userID, dbo.tbl_user.state, 
                 dbo.tbl_user.city, dbo.tbl_user.country
FROM       dbo.tbl_user, dbo.team_member
WHERE     (profile_type = 1) AND (drop_out = 0) AND team_member.userID <> tbl_user.userID
ORDER BY display_name

Open in new window

Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
haboltn

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
folderol

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
haboltn

ASKER
Thank you folderol - I knew it was something really easy :)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23