It means that those addresses are located at more than 50 units from a street. They are therefore filtered out by your (inner) JOIN
.
You can
- increase the distance in
ST_Dwithin
- or use a
LEFT JOIN
while invertingst
andad
in your query.
But your query does not return the nearest street, it returns all street/address combinations which are less than 50 m away from each other.
If you want to get the nearest street for each address, you can write for example:
SELECT DISTINCT ON (ad.gid)
ad.gid AS address_id,
st.gid AS street_id,
ad.geom AS geom
FROM ad
JOIN st ON ST_DWithin(ad.geom, st.geom, 50.0)
ORDER BY ad.gid, ST_Distance(ad.geom, st.geom)
ST_DWithin
is only used to restrict the search to streets that are less than 50 m away from the address to speed up the query if a spatial index is available.