Afficher un message
Vieux 08/02/2008, 16h26   #1
donpro
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Retrieving a list without duplicates

Hi,

I have a table called "ports" of city names index on the name which is
unique. I have a second table called "jobs" where each job is for a
single city. The relationship is that only some cities can be used as
jobs but more than one job can have the same cities

I'd like to query the "ports" table to retrieve only those cities that
appear in the jobs table so I used the following select query:

select ports.portcode, ports.name from ports
left join jobs on jobs.destinationport=ports.portcode
where ports.portcode=jobs.destinationport order by name

While the above query works, I get duplicate entries of city names
whereas I'd like only one. Any ideas on how to modify the above query
to achieve this? Using MySQL 5.0.18. Thanks in advance.

example of what I get back
--------------------------------------
Aachen
Antwerp
Antwerp
Antwerp
Hong Kong
Singapore
Singapore
Singapore
Singapore

example of what I want
---------------------------------
Aachen
Antwerp
Hong Kong
Singapore

  Réponse avec citation
 
Page generated in 0,05490 seconds with 9 queries