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

From Raymond O'Donnell
Subject Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql
Date
Msg-id 5682CE53.1030409@iol.ie
Whole thread Raw
In response to How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql  (Killian Driscoll <killiandriscoll@gmail.com>)
List 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@iol.ie


pgsql-php by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql
Next
From: Raymond O'Donnell
Date:
Subject: Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql