Join query query

From: Andrew Taylor <andydtaylor(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Join query query
Date: 2013-02-13 23:01:13
Message-ID: CAFAE3Jw+8dR5DA1OdNV53qgzC_mtHBmwh9E8o-eX9BFQiqgxDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I'd like to do something which I think should be quite easy - that is join
2 tables and create a new table.

Table A postcode_input has columns which include postcode, eastings,
northings. there are 1,687,605 rows.
Table B bng_lat_long has columns lat, lon, e, n. There are 1,687,605 rows.

eastings = e and northings = n so there should be a 1 to 1 match. The
eastings northings pair should be unique in aggregate.

So I tried doing this:

SELECT A.postcode, A.eastings, A.northings, B.lat, B.lon INTO
postcode_lat_long
FROM postcode_input AS A
LEFT JOIN bng_lat_long AS B On A.eastings = B.e AND A.northings = B.n

And ended up with a table 13,708,233 rows long with what looks like plenty
of duplicated rows. Some but not all are duplicated. What can I do to sort
this out?

Thanks,

Andy

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Carlos Henrique Reimer 2013-02-13 23:09:55 Re: Runtime variations during day
Previous Message Tom Lane 2013-02-13 22:53:21 Re: Runtime variations during day