Re: [SQL] Tricky -to me!- SQL query.

From: Remigiusz Sokolowski <rems(at)gdansk(dot)sprint(dot)pl>
To: Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Tricky -to me!- SQL query.
Date: 1999-01-12 11:44:06
Message-ID: Pine.GS4.4.02A.9901121239190.7827-100000@netra.gdansk.sprint.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
> Consider the following table:
> dev_brecard=> select * from test order by person;
> person|fruit
> ------+---------
> lucy |mandarins
> lucy |tomatoes
> lucy |pears
> lucy |oranges
> lucy |apples
> peter |pears
> peter |apples
> peter |oranges
> peter |prunes
> robert|figs
> robert|dates
> stuart|apples
> stuart|pears
> stuart|prunes
> stuart|bananas
> stuart|kumquats
> (16 rows)
>
> (code for creating and populating table is in a PS at the end of this posting)
>
> You can assume that the table is appropriately normalised and that there is
> a composite primary key for it (i.e. each COMBINATION of person and fruit
> will appear only once and neither of the fields can be NULL)
>
> How do I select from all person who like 'pears' and 'apples' (in this
> case, lucy, peter and stuart) or 'pears', 'apples' and 'oranges' (in this
> case, lucy and peter)?

What about:
SELECT person FROM test WHERE fruit='pears' AND fruit='apples' AND
fruit='oranges';
or just
SELECT person FROM test WHERE fruit IN ('pears', 'apples','oranges');

For me strange question - so I think I don't mean exactly what you do ;-)
Could You explain for what You wanna this?
Rem

-------------------------------------------------------------------*------------
Remigiusz Sokolowski e-mail: rems(at)gdansk(dot)sprint(dot)pl * *
-----------------------------------------------------------------*****----------

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stuart Rison 1999-01-12 13:41:57 Re: [SQL] Tricky -to me!- SQL query.
Previous Message Stuart Rison 1999-01-12 11:17:54 [SQL] Tricky -to me!- SQL query.