From: | "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com> |
---|---|
To: | "Bruno Wolff III" <bruno(at)wolff(dot)to>, "Kevin Jenkins" <gameprogrammer(at)rakkar(dot)org>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: SQL query question |
Date: | 2006-06-22 01:19:57 |
Message-ID: | 65937bea0606211819q33589a43r80cc325b53509c31@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Another way is to use correlated-subqueries (refrencing outer
query's columns inside a subquery; hope this feature is supported):
select *
from FileVersionHistory H1
where modificationDate = ( select max(modificationDate)
from FileVersionHistory H2
where H2.filename = H1.filename
);
And if you suspect that some different versions of a file might
have same Date, then you should add DISTINCT to 'select *', else
you'll get duplicates in the result.
Regards,
Gurjeet.
On 6/18/06, Bruno Wolff III <bruno(at)wolff(dot)to> wrote:
> On Sat, Jun 17, 2006 at 16:50:59 -0700,
> Kevin Jenkins <gameprogrammer(at)rakkar(dot)org> wrote:
> > For example
> >
> > filename date revision
> > file1 10/05/06 1
> > file1 10/05/07 2
> > file2 10/05/08 1
> >
> > I want to do a query that will return the greatest date for each
> > unique filename
>
> If the revisions for a filename are guarenteed to be ordered by date, then
> another alternative for you would be:
>
> SELECT filename, max(modificationDate), max(revision)
> FROM FileVersionHistory
> GROUP BY filename
> ;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
From | Date | Subject | |
---|---|---|---|
Next Message | Qingqing Zhou | 2006-06-22 03:01:14 | Re: Out of memory error in 8.1.0 Win32 |
Previous Message | webb.sprague | 2006-06-22 01:07:33 | Form builder? |