Only this week, get the SQL Complete Track of 9 courses in a special prize of $330 $89!
Relationships Between Geometries
8. ST_Contains
ST_Distance and ST_Dwithin
Spatial joins practice


Great job! There is one function that is very similar to ST_Within called ST_Contains. ST_Contains behaves just like ST_Within, except the order of arguments is simply reversed.

Suppose we want to find the name of the district in which Nebula Hotel is located. We can use the following query:

FROM sf_planning_districts sfn
JOIN sf_hotels sfh
ON ST_Contains(
WHERE = 'Nebula Hotel'

It's important to remember that ST_Contains(geometryA, geometryB is the same as ST_Within(geometryB, geometryA). Use whichever version makes the query more readable in your particular case.


Now it's your turn. Show the distinct names of all districts that contain ATMs of the 'Crown Financial Inc.' company.

Stuck? Here's a hint!

Use the DISTINCT clause, together with the district name in the SELECT clause. Join sf_planning_districts with sf_atms. Add a condition for a specific company name in the WHERE clause.