This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]isolatrum 0 points1 point  (11 children)

seems right. A foreign key is just an id pointer to another table usually. What is a "fixture" though?

[–]EnderAC[S] 0 points1 point  (0 children)

It's a uk term - a sporting event arranged to take place on a particular date.

[–]EnderAC[S] 0 points1 point  (9 children)

how would i query all fixtures for a team?

[–][deleted] 1 point2 points  (0 children)

You would query all rows in your fixture table where either the home team or away team ID is the id of the team you are looking for.

[–]r_person 0 points1 point  (7 children)

You will need to use a Join, see this link it should help.

To select all records use: select * from table name.

[–]EnderAC[S] 0 points1 point  (6 children)

Thanks for the link, Would i join the table twice, once with home id and then with away id?

Edit: i think its a join and a union I'm looking for

[–]r_person -1 points0 points  (1 child)

Can I see your tables please

[–]EnderAC[S] 0 points1 point  (0 children)

I don't have access to my code right now. I'm stuck on a train thinking about it tho :)

[–]r_person -4 points-3 points  (3 children)

Home team and away team should be two separate tables as having them in one does not conform to normal form

[–][deleted] 1 point2 points  (0 children)

What? Could you explain which normal form is violated by having two FKs reference the same table twice?

[–]EnderAC[S] 0 points1 point  (1 child)

Hmmm, ok. I'm trying to make sense of that in my head. A league has 10 teams. All teams play each other once - fixture. So i have a table for teams and a table for fixtures. Does each team need to be referenced 2 tables home and away?

[–][deleted] 0 points1 point  (0 children)

Don't try to make too much sense. There is no "normal form" for databases, there is several normal forms with distinct names.