Re: How to fetch rows with multiple values

From: Sebastjan Trepca <trepca(at)gmail(dot)com>
To: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to fetch rows with multiple values
Date: 2006-01-20 13:47:26
Message-ID: cd329af80601200547v2f835e0dl4fcc4c9503cc18d4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Wow, this joined query is super faster then intersect(10x), thanks a lot!!

Regarding that I have to make a join for every term, I would think it would
be more consuming. Is there any limit of joins or something similar which I
should be aware of?

Sebastjan

On 1/20/06, Michael Glaesemann <grzm(at)myrealbox(dot)com> wrote:
>
>
> 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
>
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2006-01-20 13:57:43 Re: How to convert Big5 to UTF8
Previous Message Marcos 2006-01-20 13:38:32 Re: Create Produre for DROP row