Re: A select DISTINCT query? - followup Q

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Re: A select DISTINCT query? - followup Q
Дата
Msg-id 878x2aq78x.fsf@oxford.xeocode.com
обсуждение исходный текст
Ответ на Re: A select DISTINCT query? - followup Q  (Harald Fuchs <hf0114x@protecting.net>)
Список pgsql-general
"Harald Fuchs" <hf0114x@protecting.net> writes:

> If you want to select both columns, but have uniqueness over the first
> only, you can use a derived table:
>
> SELECT tbl.name, tbl.comment
> FROM tbl
> JOIN (SELECT name FROM tbl GROUP BY name HAVING count(*) = 1) AS t
>   ON t.name = tbl.name
>

Or use the first() aggregate since you know there's only going to be one
anyways:

select name, first(comment)
  from tbl
 group by name
having count(*) = 1

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's PostGIS support!

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

Предыдущее
От: Rainer Bauer
Дата:
Сообщение: Re: Is news.postgresql.org down?
Следующее
От: Sam Mason
Дата:
Сообщение: handling of COUNT(record) vs IS NULL