Re: How to fetch rows with multiple values

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема Re: How to fetch rows with multiple values
Дата
Msg-id 65B7A0D9-F7EE-4286-9B67-009CD57796AB@myrealbox.com
обсуждение исходный текст
Ответ на How to fetch rows with multiple values  (Sebastjan Trepca <trepca@gmail.com>)
Ответы Re: How to fetch rows with multiple values  (Sebastjan Trepca <trepca@gmail.com>)
Список pgsql-general
On Jan 20, 2006, at 22:19 , Sebastjan Trepca wrote:

> What I would like is to write a query where I can specify multiple
> names and get the IDs which have them.
>
> For now it seems the most efficient way is to use INTERSECT statement:
>
> SELECT "ID" from customer_mapping WHERE "Name"='john'
> INTERSECT
> SELECT "ID" from customer_mapping WHERE "Name"='peter'

My first thought is to use a join. Does this do what you want?

select id
from customer_mapping cm1
join customer_mapping cm2 using ("ID")
where cm1."Name" = 'john
and cm2."Name" = 'peter';

> Although, I don't know how exactly to use ORDER, OFFSET and LIMIT
> in this case...

ORDER, OFFSET and LIMIT should work just fine with the JOIN query.
You could also use your intersect in a subquery and then use ORDER,
OFFSET and LIMIT on the outer query, e.g.,

select *
from (
    select "ID"...
    intersect
    select "ID" ...
) as common_names
...

Michael Glaesemann
grzm myrealbox com




В списке pgsql-general по дате отправления:

Предыдущее
От: Sebastjan Trepca
Дата:
Сообщение: How to fetch rows with multiple values
Следующее
От: Sebastjan Trepca
Дата:
Сообщение: Re: How to fetch rows with multiple values