Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id E49C72E3001 for ; Tue, 15 Jan 2008 10:03:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 41297-05-3 for ; Tue, 15 Jan 2008 10:03:31 -0400 (AST) Received: from smtpauth.rollernet.us (smtpauth.rollernet.us [208.11.75.5]) by postgresql.org (Postfix) with ESMTP id A4C732E3098 for ; Tue, 15 Jan 2008 10:03:36 -0400 (AST) Received: from smtpauth.rollernet.us (localhost.localdomain [127.0.0.1]) by smtpauth.rollernet.us (Postfix) with ESMTP id EB2BA594017; Tue, 15 Jan 2008 06:03:31 -0800 (PST) Received: from iron.denterprises.org (ool-4350518c.dyn.optonline.net [67.80.81.140]) by smtpauth.rollernet.us (Postfix) with ESMTP; Tue, 15 Jan 2008 06:03:31 -0800 (PST) Received: from [127.0.0.1] (kell.iron.denterprises.org [192.168.171.80]) by iron.denterprises.org (Postfix) with ESMTP id 0E92E1675B1; Tue, 15 Jan 2008 09:03:31 -0500 (EST) Message-ID: <478CBD22.2030204@denterprises.org> Date: Tue, 15 Jan 2008 09:03:14 -0500 From: Colin Wetherbee User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: =?UTF-8?B?TWFnbmUgTcOmaHJl?= CC: Phillip Smith , pgsql-sql@postgresql.org Subject: Re: JOIN a table twice for different values in the same query References: <002f01c853d7$63bc0680$9b0014ac@wbaus090> <47869C8C.4080109@denterprises.org> <47869EF7.70106@denterprises.org> <478CB32D.6050304@sun.com> In-Reply-To: <478CB32D.6050304@sun.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 080114-3, 01/14/2008), Outbound message X-Antivirus-Status: Clean X-Rollernet-Abuse: Processed by Roller Network Mail Services. Contact abuse@rollernet.us to report violations. Abuse policy: http://rollernet.us/abuse.php X-Rollernet-Submit: Submit ID 4410.478cbd33.c2f50.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/128 X-Sequence-Number: 29981 Magne Mæhre wrote: > Colin Wetherbee wrote: >> Colin Wetherbee wrote: >>> Phillip Smith wrote: >>>> As a side note - all the IATA codes are unique for each airport - >>>> wouldn't it be better to use these as the Primary Key and Foreign >>>> Keys? Then you wouldn't have to even join the tables unless you >>>> wanted the port names (not just the code) >>> >>> This is true, but FWIW, my application will mostly be joining for the >>> name of the airport or the city, not the code. >>> >>> I'll keep the idea of using the codes as keys in mind, though. >>> Thanks for pointing that out. >> >> Oh, now I remember why I'm using IDs as keys. ;) >> >> The code isn't always going to be an airport, and, for example, a >> train station in Buenos Aires could conceivably have the same code as >> a shipping port in Rotterdam, which, in turn, might well be JFK. :) > > Note that IATA codes are _NOT_ unique. The current list of IATA > trigrams list upward of 300 duplicate codes. If you include the train > stations, there might be additional collisions. > > You could consider using the ICAO four-letter identifiers instead. They > are unique, and are preferred by airspace management authorities. A > mapping to the corresponding IATA code exists. I have both ICAO and IATA codes in my database, but users who typically won't know (or even be aware of) ICAO codes will be using the front end. In fact, in the front end, the users will see something like the following (with the respective, unique, application-specific port ID hidden in the background). Houston, TX (IAH - George Bush Intercontinental Airport) New York, NY (JFK - John F. Kennedy International Airport) Dubai, United Arab Emirates (DXB - Dubai International Airport) Which should be unique enough. :) Colin