[postgis-users] Join gives too much data

Clay, Bruce bclay at ball.com
Thu Jul 18 13:30:12 PDT 2013


I am not sure if this is a good place for this question but here goes.
 
I have a table with 162 records of data including a reference ID and project_ids and a separate table with many more records with different information but also includes the reference ID.
 
when I perform a 
 
Select a.field_one, a. field_two, b.field_one etc
  from table_one a, table_two b
  where a.ref_id = b.ref_id and a.project_id = b.project_id
 
or 
 
Select a.field_one, a. field_two, b.field_one etc
  from table_one a INNER JOIN ON table_two b
  where a.ref_id = b.ref_id and a.project_id = b.project_id
 
I get more records back than exist in table_one
 
the ref_id is in table_b multiple time but each time there is a different project_id.
 
I can limit some of the repeats by putting distinct after the select but then I only get 162 records instead of the 162 records expected.
 
I get the same results in pgAdmin as I do in a postGis c++ call.
 
Is there a better way to write the SQL so I get exactly the same number of records as are in tabl_a
 
Bruce



This message and any enclosures are intended only for the addressee.  Please 
notify the sender by email if you are not the intended recipient.  If you are 
not the intended recipient, you may not use, copy, disclose, or distribute this 
message or its contents or enclosures to any other person and any such actions 
may be unlawful.  Ball reserves the right to monitor and review all messages 
and enclosures sent to or from this email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20130718/95241679/attachment.html>


More information about the postgis-users mailing list