Search Postgresql Archives

Re: A select DISTINCT query? - followup Q

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Harald Fuchs" <hf0114x@xxxxxxxxxxxxxx> 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!

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux