If I have a match table ( id , details) and team table (id,name) and I want to get all matches played by a given two teams.
My solution is:
Create a third table contains on (match_id,team1_id,team2_id)
Is this the best practice in this case ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming a match can be played only by two tables, the team1_id and team2_id should be part of the
matchtable itself as attributes. A separate table is not needed. You can also define FOREIGN KEY relationship between team1_id and team table’s id and the same for team2_id also.A third table would be needed for a match that can be played by multiple teams and in such case the table structure would be (
match_id,team_id) where there will multiple records with same match_id, i.e. one-to-many relationship between match table and match_teams table.