| From: | Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk> |
|---|---|
| To: | fmorton(at)base2inc(dot)com, pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Select Maximum Question |
| Date: | 1999-08-13 08:40:02 |
| Message-ID: | v04020a00b3d9891cf856@[128.40.242.190] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
>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".
Try
SELECT filename,max(revision) FROM <table>
GROUP BY filename;
You can add a WHERE clause before the GROUP BY to only look at certain
filenames (e.g. WHERE filename~'foo') or if you're looking for files with a
specific latest revision number (e.g. WHERE revision=3) and an ORDER BY
after the GROUP BY (e.g. ORDER BY filename).
HTH,
S.
+--------------------------+--------------------------------------+
| Stuart C. G. Rison | Ludwig Institute for Cancer Research |
+--------------------------+ 91 Riding House Street |
| N.B. new phone code!! | London, W1P 8BT |
| Tel. +44 (0)207 878 4041 | UNITED KINGDOM |
| Fax. +44 (0)207 878 4040 | stuart(at)ludwig(dot)ucl(dot)ac(dot)uk |
+--------------------------+--------------------------------------+
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Roberto Moreda | 1999-08-13 09:34:22 | About triggers |
| Previous Message | Duncan Kinder | 1999-08-13 07:13:09 | Environmental Variables |