Home > Software design >  How to get columns from a two table which are divided with one to many and many to many relation?
How to get columns from a two table which are divided with one to many and many to many relation?

Time:03-02

I know It's a very basic question for some of you, but I'm really struggling with it. Graph for better understanding

I have to get the names of the people that are climbing the specific mountain (mount Fuji).

What I have tried so far:

SELECT climber.first_name||' is going to climb '||mountain.mountain_name FROM climber 
INNER JOIN mountain ON mountain.mountain_id=climbing.mountain 
INNER JOIN climbing ON climbing.climbing_id=climbing_participants.climbing_id
INNER JOIN climbing_participants ON climbing_participants.climber_id=climber.climber_id;

CodePudding user response:

SELECT climber.first_name||' is going to climb '||mountain.mountain_name 
FROM climber 
INNER JOIN climbing_participants ON climbing_participants.climber_id=climber.climber_id
INNER JOIN climbing ON climbing.climbing_id=climbing_participants.climbing_id
INNER JOIN mountain ON mountain.mountain_id=climbing.mountain 
  • Related