Re: Simple Query?

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Koen Bok <koen(at)madebysofa(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Simple Query?
Date: 2007-09-11 21:59:37
Message-ID: 7012.26158.qm@web31806.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

--- Koen Bok <koen(at)madebysofa(dot)com> wrote:
> I am doing some optimization on our search, but I need some advise...
>
> table: item
>
> id name
> --------------------------------------
> 1 iPod
> 2 Zune
> 3 Walkman
>
> table: search_item
>
> id_search id_item
> --------------------------------------
> 1 1
> 1 2
> 1 3
> 2 2
> 2 3
> 3 1
> 3 3
>
>
> Now what I want to have is the items that match with id_search 1 and
> 2 and 3. Therefore I use the following SQL query.

SELECT id_search
FROM Search_item
GROUP BY id_search
HAVING Count( * ) = 3
AND Max( id_item ) = 3
AND Min( id_item ) = 1;

Regards,
Richard Broersma Jr.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message ogjunk-pgjedan 2007-09-12 00:06:12 Extracting hostname from URI column
Previous Message Rodrigo De León 2007-09-11 21:46:17 Re: Simple Query?