pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: Tim Perdue <perdue@raccoon.com>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Group By Dilemma
Date: Fri, 04 Jun 1999 08:41:52 +0100
Message-ID: <199906040741.IAA04924@linda.lfix.co.uk> (raw)
In-Reply-To: <perdue@raccoon.com> <001801beae2c$354dd580$0b8c5aa5@timnt.weather.net>

"Tim Perdue" wrote:
  >Hello, I am trying to do a GROUP BY so that I can get a count of messages
  >with the same subject. The problem is, the optimizer won't let me group by
  >just one column, when I am selecting several columns.
  
You can only have the grouped column and aggregates in your query.

  >I suppose Postgres doesn't know which rows to leave out and which ones to
  >display, but I'm hoping someone can offer a solution....
  >
  >SELECT
  >fld_mailid,
  >fld_mail_date,
  >fld_mail_is_followup,
  >fld_mail_from,
  >fld_mail_subject,   <-- Group only on this, so I can get a count
  >count(*)
  >FROM tbl_mail_archive
  >WHERE fld_mail_list=1 AND
  >fld_mail_year=1999 AND
  >fld_mail_month=06
  >group by fld_mail_subject
  >ORDER BY fld_mail_date DESC
  >LIMIT 26 OFFSET 0;

What do you expect to see in the other columns?  Why are you including
them at all?

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
               PGP key from public servers; key ID 32B8FAA1
                 ========================================
     "But without faith it is impossible to please him; for 
      he that cometh to God must believe that he is, and 
      that he is a rewarder of them that diligently seek 
      him."       Hebrews 11:6 





view thread (2+ messages)

Message-ID: <199906040741.IAA04924@linda.lfix.co.uk>
Permalink:  ../199906040741.IAA04924@linda.lfix.co.uk/
Also on:    postgresql.org/message-id/199906040741.IAA04924@linda.lfix.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: olly@lfix.co.uk, perdue@raccoon.com, pgsql-sql@hub.org
  Subject: Re: [SQL] Group By Dilemma
  In-Reply-To: <199906040741.IAA04924@linda.lfix.co.uk>
  References: <199906040741.IAA04924@linda.lfix.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox