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

Raymond O'Donnell <[email protected]> Tue, 29 Dec 2015 18:17:55 +0000
Newsgroups gmane.comp.db.postgresql.php
Message-ID <[email protected]>
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
[email protected]


-- 
Sent via pgsql-php mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php