Re: Having difficulty writing a "best-fit" query..

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: "Jamie Tufnell" <diesql(at)googlemail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Having difficulty writing a "best-fit" query..
Date: 2007-10-16 17:11:16
Message-ID: a55915760710161011g6f67bbdege536dc3f8ac22342@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 10/16/07, Jamie Tufnell <diesql(at)googlemail(dot)com> wrote:
> I'm taking a subset of all my genres, and I want to get ONE row for each
> movie in the subset alongside its most appropriate genre (whichever has the
> highest relevance). In other words, the best fit.

You didn't provide the expected output, but try:

SELECT *
FROM t tt
WHERE relevance = (SELECT MAX(relevance)
FROM t
WHERE movie_id = tt.movie_id)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2007-10-16 17:14:59 Re: Having difficulty writing a "best-fit" query..
Previous Message Jamie Tufnell 2007-10-16 16:46:33 Having difficulty writing a "best-fit" query..