That's right! The functions ST_DWithin
and ST_Distance
can be used interchangeably in an ON
condition. If you're looking for ATMs located within 1000 meters of Nourish Hotel, you can use ST_Dwithin
:
SELECT
sfh.name,
sfa.id,
ST_Distance(
ST_Transform(
sfh.boundaries, 26910),
ST_Transform(
sfa.coordinates, 26910)) AS distance
FROM sf_hotels sfh
JOIN sf_atms sfa
ON ST_DWithin(
ST_Transform(sfh.boundaries, 26910),
ST_Transform(
sfa.coordinates, 26910), 1000)
WHERE sfh.name = 'Nourish Hotel'
ORDER BY distance DESC;
Alternatively, you can use ST_Distance
to get the same:
SELECT
sfh.name,
sfa.id,
ST_Distance(
ST_Transform(
sfh.boundaries, 26910),
ST_Transform(
sfa.coordinates, 26910)) AS distance
FROM sf_hotels sfh
JOIN sf_atms sfa
ON ST_Distance(
ST_Transform(
sfh.boundaries, 26910),
ST_Transform(
sfa.coordinates, 26910)) < 1000
WHERE sfh.name = 'Nourish Hotel'
ORDER BY distance DESC;