mysql help please

mysql help please

am 05.07.2006 22:04:21 von Bob Bedford

I've ever the same problem.

Table1
idperson, name, zip

table2
zip, city, region.

Table2: same zip, many cities (1000, Lausanne - 1000, Lausanne1, ...)

Now I'd like ONE query wich return the name, zip and city, but just one
record per zip.

I mean if a record in table1 has zip 1000, I only want the first occurence
of the city (in my case Lausanne).
Actually I get as many records as they are cities with the same zip.

namex,1000,Lausanne
namex,1000,Lausanne1
namex,1000,LausanneN....

How to do so ? in fact what I need is count the number of peoples in a
region, and the region is linked to a zip.

1000, Lausanne, VD
1000, Lausanne1, VD....

the actual query is
select count(idperson), region from table1 inner join table2 on table1.zip =
table2.zip group by region.
Please help.

Bob

Re: mysql help please

am 07.07.2006 01:35:33 von Johannes Vogel

Hi Bob

Bob Bedford wrote:
> zip, city, region.
> Table2: same zip, many cities (1000, Lausanne - 1000, Lausanne1, ...)
> Now I'd like ONE query wich return the name, zip and city, but just one
> record per zip.

Two ways to solve:
select name, distinct(zip), city from ...;
select name, zip, city from ... group by zip;

Both of them should solve your problems.
Johannes