Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aDyqY-0006YE-0D for pgsql-php@arkaria.postgresql.org; Tue, 29 Dec 2015 18:18:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aDyqX-0003H8-JG for pgsql-php@arkaria.postgresql.org; Tue, 29 Dec 2015 18:18:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aDyqX-0003H2-5s for pgsql-php@postgresql.org; Tue, 29 Dec 2015 18:18:09 +0000 Received: from teladesign.vm.bytemark.co.uk ([89.16.172.204]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aDyqU-0003K8-Gh for pgsql-php@postgresql.org; Tue, 29 Dec 2015 18:18:07 +0000 Received: from [109.76.177.57] (helo=[127.0.0.1]) by teladesign.vm.bytemark.co.uk with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aDyqS-0003MV-03; Tue, 29 Dec 2015 18:18:04 +0000 Reply-To: rod@iol.ie Subject: Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql References: <5682B63E.9030008@iol.ie> <5682BBF3.1020605@iol.ie> <5682C041.40706@iol.ie> To: Killian Driscoll , PostgreSQLPHP From: Raymond O'Donnell X-Enigmail-Draft-Status: N1110 Message-ID: <5682CE53.1030409@iol.ie> Date: Tue, 29 Dec 2015 18:17:55 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-php Precedence: bulk Sender: pgsql-php-owner@postgresql.org On 29/12/2015 17:24, Killian Driscoll wrote: > So it should be: > exists select [whatever] > from country_table ct > inner join lookup_table lt on (ct.country_type_id = lt.country_type_id) > [etc] > > [whatever] [etc] - what are these? Apologies - [whatever] stood for whatever columns you might want to return from the query, for example: select country_id, col2, col3, [...] from .... In the case of the subquery inside EXISTS, however, it doesn't matter what you return - all EXISTS tests is whether or not any rows are returned. In this instance, it's common simply to write select 1 from .... The [etc] stood for any clauses that might follow the WHERE clause, such as ORDER BY. You don't need ORDER BY in the EXISTS test, as again all you're checking is whether or not any rows are returned - it doesn't matter what order their in. So, short version, what you probably need is just: exists select 1 from country_table ct inner join lookup_table lt on (ct.country_type_id = lt.country_type_id) Hope this helps, Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie -- Sent via pgsql-php mailing list (pgsql-php@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-php