Search Postgresql Archives

Re: A select DISTINCT query? - followup Q

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

 



Hi Phil,
Each of columns that you specify in your SELECT clause, must also appear in the GROPU BY clause.

SELECT COUNT(*) AS cnt, name, comment, ...
FROM tst
GROUP BY name, comment, ...
HAVING COUNT(*) = 1;


Phil Rhoades wrote:
People,


select count(*) as cnt, name from tst group by name having count(*) = 1


This worked for my basic example but not for my actual problem - I get
"column comment must appear in the GROUP BY clause or be used in an
aggregate function" errors so I have a related question:

With table:

name comment

1    first comment
2    second comment
3    third comment
3    fourth comment
4    fifth comment
5    sixth comment

- how can I use something like the previous select statement but where
the comment field does not appear in the "group by" clause and gives the
following result:

1    first comment
2    second comment
4    fifth comment
5    sixth comment

Thanks,

Phil.

Mike Ginsburg
Collaborative Fusion, Inc.
mginsburg@xxxxxxxxxxxxxxxxxxxxxxx
412-422-3463 x4015

--
****************************************************************
IMPORTANT: This message contains confidential information
and is intended only for the individual named. If the reader of
this message is not an intended recipient (or the individual
responsible for the delivery of this message to an intended
recipient), please be advised that any re-use, dissemination,
distribution or copying of this message is prohibited. Please
notify the sender immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The
sender therefore does not accept liability for any errors or
omissions in the contents of this message, which arise as a
result of e-mail transmission.
****************************************************************




---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

[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