Re: Best way to "and" from a one-to-many joined table?

From: "Oliveiros Cristina" <oliveiros(dot)cristina(at)gmail(dot)com>
To: "Bryce Nesbitt" <bryce2(at)obviously(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, milan(dot)opa(at)gmail(dot)com
Subject: Re: Best way to "and" from a one-to-many joined table?
Date: 2008-12-10 19:21:02
Message-ID: f54607780812101121p429122bfk16f2d90818583094@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

*How can I get an AND search (people with Dark Hair AND who are President)?*

The two joins didn't work?
Or were they too slow ?

Best,
Oliveiros

2008/12/10 Bryce Nesbitt <bryce2(at)obviously(dot)com>

>
>
> Milan Oparnica wrote:
> > This is how I do it, and it runs fast:
> > select p.*
> > from test_people p inner join test_attributes a on p.people_id =
> > a.people_id
> > where a."attribute" = @firstAttr or a."attribute" = @secondAttr
> But that does an "or" search, not "and", returning Satan in addition to
> Obama:
>
> select * from test_people p inner join test_attributes a on p.people_id
> = a.people_id
> lyell5-> where a."attribute" = 'Dark Hair' or a."attribute" = 'USA
> President';
> +-----------+-------------+-----------+---------------+
> | people_id | person_name | people_id | attribute |
> +-----------+-------------+-----------+---------------+
> | 8 | Obamba | 8 | USA President |
> | 8 | Obamba | 8 | Dark Hair |
> | 8 | Obamba | 8 | Dark Hair |
> | 10 | Satan | 10 | Dark Hair |
> +-----------+-------------+-----------+---------------+
>
> How can I get an AND search (people with Dark Hair AND who are President)?
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Maier 2008-12-10 19:55:51 Is it possible to only allow deletes from a table via referential integrity cascades?
Previous Message Bryce Nesbitt 2008-12-10 18:54:29 Re: Best way to "and" from a one-to-many joined table?