I have 4 tables which were auto generated for me:
- User
- Challenge
- Exercise
- Challenge_Exercise
One User may have many Challenges, and one Challenge will have many Exercises.
What I noticed is that the Challenge table has a reference to it’s parent User (called user_id) but Exercise do not have a reference in it’s table to Challenge; their relation is stored in Challenge_Exercise as Challenge_id and exercise_id.
My question is, how would I take out every Exercise that is linked to a specific user? For instance User with id = 1?
What I’m doing here is a
join, you could also explicitly do it withinner joins(google it if you wanna know more).This table is needed because you have a
many to manyrelationship, which means each challenge can have multiple exercises, but also each exercise can have multiple challenges. It’s a standard to make an extra table then, so you don’t have redundant data, this table is often calledjunction table.If you want background just google it, there are tons of data to this topic.