Monday, March 12, 2012

Find records with same values in a field

I have a table of postcodes and I want to find out which towns have the same
postcodes
e.g.
Table has these values
Bournemouth B34
Brighton B24
Chelmsford B34
I want to write the query which returns me Bournemouth and Chelmsford (based
on the postcode being the same and the town being different).
Any ideas please.
ThxHi,
select pc.City, pc.PostalCode
from PostalCode pc
inner join PostalCode pc1
on pc1.PostalCode=pc.PostalCode
where pc1.city<>pc.city
"Billy" wrote:

> I have a table of postcodes and I want to find out which towns have the sa
me
> postcodes
> e.g.
> Table has these values
> Bournemouth B34
> Brighton B24
> Chelmsford B34
> I want to write the query which returns me Bournemouth and Chelmsford (bas
ed
> on the postcode being the same and the town being different).
> Any ideas please.
> Thx|||Thank you
"Billy" wrote:

> I have a table of postcodes and I want to find out which towns have the sa
me
> postcodes
> e.g.
> Table has these values
> Bournemouth B34
> Brighton B24
> Chelmsford B34
> I want to write the query which returns me Bournemouth and Chelmsford (bas
ed
> on the postcode being the same and the town being different).
> Any ideas please.
> Thx|||On Mon, 14 Feb 2005 01:41:11 -0800, Billy wrote:

>I have a table of postcodes and I want to find out which towns have the sam
e
>postcodes
(snip)
Hi Billy,
SELECT a.Postcode, a.Town, b.Town
FROM MyTable AS a
INNER JOIN MyTable AS b
ON b.Postcode = a.Postcode
AND b.Town > a.Town
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

No comments:

Post a Comment