Take the tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This seems too simple to be asking this but I am really new to postgis/postgres have been going around in circles with this. I am performing a really simple spatial query where I would like to make a subset of a table of points conditional on whether they are contained within a polygon in another table.

I can return the rows I want from my table, however, they are being joined to the other table. All I want is a subset of one table based on the condition, not a join per se.

Here's my query:

SELECT * 
FROM
public."KDhh_survey",
public."ur_pilot_survey"
WHERE
ST_contains(public."ur_pilot_survey".the_geom, public."KDhh_survey".the_geom);

I only want the records in table public."KDhh_survey" returned in a new table or view, but ALL records are returned from both and a join created.

I promise I have searched high and low for an answer to this, but every example I found for ST_contains is based on spatially joining two table together. I really only want to query my data set, so that I can create a subset of my original table.

Any help, really appreciated!

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

You just need "KDhh_survey".* in your Select

SELECT "KDhh_survey".* 
FROM
public."KDhh_survey",
public."ur_pilot_survey"
WHERE
ST_contains(public."ur_pilot_survey".the_geom, public."KDhh_survey".the_geom);
share|improve this answer
 
ha! thank you sir, I clearly should have gone to bed hours ago... –  marty_c Aug 15 at 2:03
1  
@marty_c : if answer is coorect you should mark question answered –  simplexio Aug 15 at 7:42
add comment

thanks @ Nathan W for answering my quesiton:

You just need "KDhh_survey".* in your Select

SELECT "KDhh_survey".* FROM public."KDhh_survey", public."ur_pilot_survey" WHERE ST_contains(public."ur_pilot_survey".the_geom, public."KDhh_survey".the_geom);

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.