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

* Select Maximum Question
@ 1999-08-12 15:51 Frank Morton <fmorton@base2inc.com>
  1999-08-12 23:01 ` Re: [SQL] Select Maximum Question Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Frank Morton @ 1999-08-12 15:51 UTC (permalink / raw)
  To: pgsql-sql

I am a SQL newbie, so hang in there with me.

I have two fields in a table, "filename" and "revision".
The table contains 3 rows where the filename is the same and
revision contains "1" "2" and "3" in each respective row.
It also contains another row for a different filename with
revision set to "1".

I want to do a select which only returns the highest revision
level for each filename, so the select will return two rows,
the first filename with revision = "3" and the second filename
with revision set to "1".

How do I do this? I imagine this is simple, but it is new to me.

Thanks.





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

* Re: [SQL] Select Maximum Question
  1999-08-12 15:51 Select Maximum Question Frank Morton <fmorton@base2inc.com>
@ 1999-08-12 23:01 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 1999-08-12 23:01 UTC (permalink / raw)
  To: Frank Morton <fmorton@base2inc.com>; +Cc: pgsql-sql

"Frank Morton" <fmorton@base2inc.com> writes:
> I want to do a select which only returns the highest revision
> level for each filename,

Try something like

	SELECT filename, max(revision) FROM table GROUP BY filename;

When you use GROUP BY, aggregate functions like max() are applied
separately over each group --- which is just what you want for this
problem.

			regards, tom lane



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


end of thread, other threads:[~1999-08-12 23:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-08-12 15:51 Select Maximum Question Frank Morton <fmorton@base2inc.com>
1999-08-12 23:01 ` Tom Lane <tgl@sss.pgh.pa.us>

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