pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Group By Dilemma
2+ messages / 2 participants
[nested] [flat]

* Group By Dilemma
@ 1999-06-04 01:47 Tim Perdue <perdue@raccoon.com>
  1999-06-04 07:41 ` Re: [SQL] Group By Dilemma Oliver Elphick <olly@lfix.co.uk>
  0 siblings, 1 reply; 2+ messages in thread

From: Tim Perdue @ 1999-06-04 01:47 UTC (permalink / raw)
  To: pgsql-sql@hub.org

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.

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;

Tim Perdue
PHPBuilder.com / GotoCity.com / Geocrawler.com






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] Group By Dilemma
  1999-06-04 01:47 Group By Dilemma Tim Perdue <perdue@raccoon.com>
@ 1999-06-04 07:41 ` Oliver Elphick <olly@lfix.co.uk>
  0 siblings, 0 replies; 2+ messages in thread

From: Oliver Elphick @ 1999-06-04 07:41 UTC (permalink / raw)
  To: Tim Perdue <perdue@raccoon.com>; +Cc: pgsql-sql@hub.org

"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 





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1999-06-04 07:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-06-04 01:47 Group By Dilemma Tim Perdue <perdue@raccoon.com>
1999-06-04 07:41 ` Oliver Elphick <olly@lfix.co.uk>

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