Strange Join question

Поиск
Список
Период
Сортировка
От Noah Silverman
Тема Strange Join question
Дата
Msg-id 1B62AFA4-2A41-11D7-8B2D-000393AA8F3C@allresearch.com
обсуждение исходный текст
Ответ на Re: 7.3.1 New install, large queries are slow  ("Josh Berkus" <josh@agliodbs.com>)
Список pgsql-performance
Hi,

I have a challenging (for me) SQL question:

Two tables
(Note: these are fictitious, the real tables actually make sense, so no
need to re-design our table structure)

Table 1
id | name | count
------------------------
1 |   foo    |  10
1 |   foo    |  20
2 |  bar     |  100


Table 2
id  | f1  | f2  | t1ref
-----------------------
1  | 10  |  20 | 1
2  | 50  | 40  | 2


The question:

I want to do the following select:
select table2.f1, table1.name   from table1,table2 where table1.id =
table 2.id and table2.id = 2;

The problem is that I really only need the name from table2 returned
once.  With this query, I get two records back.  Clearly this is
because of the join that I am doing.  Is there a different way to
perform this join, so that I only get back ONE record from table1 that
matches?

Thanks,

-Noah


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

Предыдущее
От: "Josh Berkus"
Дата:
Сообщение: Re: 7.3.1 New install, large queries are slow
Следующее
От: Tom Lane
Дата:
Сообщение: Re: 7.3.1 New install, large queries are slow