Changes between Version 1 and Version 2 of UsersWikiExamplesAntiNear
- Timestamp:
- 04/14/09 08:52:57 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UsersWikiExamplesAntiNear
v1 v2 8 8 Solution: This example uses the trick that the primary key or non-nullable field of the right table in a left join will return NULL only in the situation where there is no match to the left table. So here we first ask the question what hospitals are within 3000 meters from each location and then we throw out all the records that have hospitals within that distance. 9 9 10 {{{ 10 11 SELECT l.location_name 11 12 FROM locations As l … … 13 14 WHERE h.hospital_id IS NULL; 14 15 16 }}} 15 17 16 18 Another way of solving the same problem: 17 19 20 21 {{{ 18 22 SELECT l.location_name 19 23 FROM locations As l 20 24 INNER JOIN hospitals h ON not ST_DWithin(l.the_geom, h.the_geom,3000); 21 25 26 }}} 27 28 22 29 We just switch the result of the boolean question ST_DWithin and get the ones not matching. 23 30 24 or maybe 31 or maybe: 25 32 33 {{{ 26 34 SELECT l.location_name 27 35 FROM locations As l, hospitals h 28 36 WHERE not ST_DWithin(l.the_geom, h.the_geom,3000); 37 38 }}}