471,893 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

SQL many-to-many query problem. HELP !

I have 3 tables:

1. tblSports which has an ID and Sport columns (basketball, baseball,
football, and volleyball)

2. tblTeams with an ID and Team columns (TeamsA to D)

3. tblJoin which has two foreign key columns (ID for Sports, ID for
Teams) This is where teams are joined to whatever Sports they play.


1. How should I do my select statement when given the team
it'll show the sports they do NOT play?

2. Just the opposite of the 1st. Given the sport, what teams do NOT

Thanks in advance for your help.
Jul 20 '05 #1
2 1213
SELECT S.sport_id, S.sport_name
FROM tblSports AS S
FROM tblJoin
WHERE sport_id = S.sport_id
AND team_id = ???)

SELECT T.team_id, T.team_name
FROM tblTeams AS T
FROM tblJoin
WHERE team_id = T.team_id
AND sport_id = ???)

David Portas
SQL Server MVP
Jul 20 '05 #2
Thanks a lot.

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by YoBro | last post: by
3 posts views Thread by luis.c.torres | last post: by
1 post views Thread by hardik | last post: by
29 posts views Thread by wizofaus | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.