<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi John,<br>
<br>
How about this, off the top of my head:<br>
<br>
select itemid, name, max(number)<br>
from table<br>
group by itemid, name<br>
order by name, itemid<br>
<br>
Regards,<br>
<br>
Bevan<br>
<br>
<br>
<div class="moz-cite-prefix">On 10/11/2013 20:09, John C wrote:<br>
</div>
<blockquote cite="mid:000001cedde3$cabcab40$603601c0$@co.nz"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0mm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Arial","sans-serif";
        color:blue;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">Hi
all<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">Can
anybody help me with the following query?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">I
have a table like:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><u><span
style="font-family:"Arial","sans-serif";color:blue">ItemID
Name Number<o:p></o:p></span></u></b></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">234
Washer 100<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">234
Washer 120<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">234
Washer 105<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">500
Nut 520<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">500
Nut 502<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">500
Nut 501<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">What
I would like to see is a for each ItemID the highest Number
sorted by Name.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">My
sql is like:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span
style="font-family:"Arial","sans-serif";color:blue">SELECT
*<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span
style="font-family:"Arial","sans-serif";color:blue">FROM
Table<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span
style="font-family:"Arial","sans-serif";color:blue">GROUP
BY ItemID<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span
style="font-family:"Arial","sans-serif";color:blue">ORDER
BY Name, Number<o:p></o:p></span></b></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">What
returns is:<o:p></o:p></span></p>
<p class="MsoNormal"><b><u><span
style="font-family:"Arial","sans-serif";color:blue">ItemID
Name Number<o:p></o:p></span></u></b></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">234
Washer 105<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">500
Nut 501<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">It
seems to return the last record for each item. How can I get
the highest number for each Item?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">Thanks
a lot for any help.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Arial","sans-serif";color:blue">John
C<o:p></o:p></span></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: <a class="moz-txt-link-abbreviated" href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a>
Admin: <a class="moz-txt-link-freetext" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a>
Unsubscribe: send an email to <a class="moz-txt-link-abbreviated" href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</pre>
</blockquote>
<br>
</body>
</html>