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

Поиск
Список
Период
Сортировка
От Bryce Nesbitt
Тема Re: Best way to "and" from a one-to-many joined table?
Дата
Msg-id 49401065.80700@obviously.com
обсуждение исходный текст
Ответ на Re: Best way to "and" from a one-to-many joined table?  (Milan Oparnica <milan.opa@gmail.com>)
Ответы Re: Best way to "and" from a one-to-many joined table?  ("Oliveiros Cristina" <oliveiros.cristina@gmail.com>)
Список pgsql-sql

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)?



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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Is there a bug in PostgreSQL ?
Следующее
От: "Oliveiros Cristina"
Дата:
Сообщение: Re: Best way to "and" from a one-to-many joined table?