Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Killian Driscoll <killiandriscoll(at)gmail(dot)com>, PostgreSQLPHP <pgsql-php(at)postgresql(dot)org>
Subject: Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql
Date: 2015-12-29 18:17:55
Message-ID: 5682CE53.1030409@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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(at)iol(dot)ie

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Raymond O'Donnell 2015-12-29 19:28:53 Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql
Previous Message Raymond O'Donnell 2015-12-29 17:17:53 Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql