Path: news.easynews.com!core-easynews!newsfeed1.easynews.com!easynews.com!easynews!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!feed.cgocable.net!newsfeed.torontointernetxchange.net!radon.golden.net!mantis.golden.net!not-for-mail
From: "Bob Badour" <bbadour@golden.net>
Newsgroups: comp.databases.theory
References: <f7359f44.0304240551.20a3a079@posting.google.com>
Subject: Re: getting the maximum from multiple returns
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <iwUpa.618$dX4.122720314@mantis.golden.net>
Date: Thu, 24 Apr 2003 12:04:46 -0400
NNTP-Posting-Host: 207.35.144.74
X-Complaints-To: abuse@golden.net
X-Trace: mantis.golden.net 1051202702 207.35.144.74 (Thu, 24 Apr 2003 12:45:02 EDT)
NNTP-Posting-Date: Thu, 24 Apr 2003 12:45:02 EDT
Organization: Golden Triangle On Line Inc.
Xref: core-easynews comp.databases.theory:25958
X-Received-Date: Thu, 24 Apr 2003 09:12:30 MST (news.easynews.com)

"Michael Sterling" <stermic@gw.co.jackson.mo.us> wrote in message
news:f7359f44.0304240551.20a3a079@posting.google.com...
> i have a query where i'm attempting to select the maximum of the
> records returned. that is to say it will return multiple records with
> the same primary key

If it were a primary key, there could be no multiple records or tuples.


> and of those i want the one with the highest
> percentage as indicated in the sample of returned data below. what my

What you want is a quota query (TOP N)--in this case a TOP 1. Since SQL has
no direct support for quota queries, all of the valid phrasings in SQL are
rather complex.

I suggest using a scalar correlated subquery in your WHERE clause

ie. where perc_complete = ( select max(perc_complete)....)


