Scott
Scott

Reputation: 4210

Need help with TSQL proc

So I have a mapping table of tournaments to teams. All this table has is TeamId and TournamentId.

I have a proc, GetTournamentsByTeam that takes in @TeamId int

Basically I want to get all the tournament records from tblTournament using all the TournamentId's I get from the mapping table where the TeamId = @TeamId.

How would I do this?

Upvotes: 1

Views: 45

Answers (2)

Pavel Urbančík
Pavel Urbančík

Reputation: 1496

What you want to do is read any SQL book for beginners. Seriously.

Upvotes: 0

Rebecca Chernoff
Rebecca Chernoff

Reputation: 22605

What you want to do is an inner join between the tables.

SELECT     tournament.*
FROM       tblTournament tournament
INNER JOIN tblTournamentTeams tt ON tournament.TournamentId = tt.TournamentId
WHERE      tt.TeamId = @TeamId

Upvotes: 1

Related Questions