How to make an SQL query that spans multiple tables?

Hi! There is here such table:

5cf64a7b07c13063950668.png
________________________________________________________________________________________________________________________________________

people - people
planet - planet
planet_resource resources that are present on the planets
people_planet - mapping of planets and people who have access
planet_resource_person - comparison of the planets resources and people who have access to them

As can be seen from the tables, several people may have access to the same planet, but with possible different access to resources, including a complete lack of access to resources.

Note the question) for a specific person to a list of planets where he has access to at least one resource? For example, Victor has access to Venus and Earth, but access resources only on Venus - that is, the query result should be the row with id=2 from table planet.
March 23rd 20 at 19:02
2 answers
March 23rd 20 at 19:04
Solution
It is necessary not only to communicate, but also to isolate the unique data de-duplication here will help guide DISTINCT:
SELECT DISTINCT
planet.*
FROM
planet
INNER JOIN
planet_resource
ON
 planet_resource.planet_id = planet.id
INNER JOIN
planet_resource_person
ON
 planet_resource_person.resource_id is = planet_resource.id
INNER JOIN
people_planet
ON
 people_planet.people_id = planet_resource_person.person_id
 AND people_planet.planet_id = planet.id
WHERE
 people_planet.people_id = ID the right person
Excellent answer! A special thank you for not lazy to write query code. Hope will help someone else! - Mauricio.Beier commented on March 23rd 20 at 19:07
March 23rd 20 at 19:06
To link JOIN.

Find more questions by tags SQL