Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id C41342E2DA1 for ; Tue, 15 Jan 2008 09:21:15 -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 91157-02 for ; Tue, 15 Jan 2008 09:21:05 -0400 (AST) Received: from gmp-eb-mail-2.sun.com (gmp-eb-mail-2.sun.com [192.18.6.24]) by postgresql.org (Postfix) with ESMTP id 094A72E0385 for ; Tue, 15 Jan 2008 09:21:09 -0400 (AST) Received: from fe-emea-09.sun.com (gmp-eb-lb-2-fe1.eu.sun.com [192.18.6.10]) by gmp-eb-mail-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id m0FDL331027270 for ; Tue, 15 Jan 2008 13:21:06 GMT Received: from conversion-daemon.fe-emea-09.sun.com by fe-emea-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) id <0JUO00K01T0A7200@fe-emea-09.sun.com> (original mail from Magne.Mahre@Sun.COM) for pgsql-sql@postgresql.org; Tue, 15 Jan 2008 13:21:03 +0000 (GMT) Received: from [129.159.112.248] by fe-emea-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTPSA id <0JUO008QHT2LW7A0@fe-emea-09.sun.com>; Tue, 15 Jan 2008 13:20:48 +0000 (GMT) Date: Tue, 15 Jan 2008 14:20:45 +0100 From: =?UTF-8?B?TWFnbmUgTcOmaHJl?= Subject: Re: JOIN a table twice for different values in the same query In-reply-to: <47869EF7.70106@denterprises.org> To: Colin Wetherbee Cc: Phillip Smith , pgsql-sql@postgresql.org Message-id: <478CB32D.6050304@sun.com> Organization: Sun Microsystems Inc. MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=UTF-8 Content-transfer-encoding: 7BIT References: <002f01c853d7$63bc0680$9b0014ac@wbaus090> <47869C8C.4080109@denterprises.org> <47869EF7.70106@denterprises.org> User-Agent: Thunderbird 2.0.0.9 (X11/20071119) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/126 X-Sequence-Number: 29979 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. --Magne