<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><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;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 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";
        color:black;}
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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0mm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Arial","sans-serif";
        color:blue;
        font-weight:normal;
        font-style:normal;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas","serif";
        color:black;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:blue;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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]--></head><body bgcolor=white lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>Thanks guys<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 found the problem; I should have assigned <b>max(Number)</b> <b>AS Number</b>, as further up in my code it could not find the field "<b>max(Number)</b>", but now with "AS Number" it is all working.<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'>Cheers<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>John<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'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0mm 0mm 0mm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> delphi-bounces@listserver.123.net.nz [mailto:delphi-bounces@listserver.123.net.nz] <b>On Behalf Of </b>Bevan Edwards<br><b>Sent:</b> Sunday, 10 November 2013 8:16 p.m.<br><b>To:</b> NZ Borland Developers Group - Delphi List; NZ Borland Developers Group - Delphi List<br><b>Subject:</b> Re: [DUG] sql - GROUP<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>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><o:p></o:p></p><div><p class=MsoNormal>On 10/11/2013 20:09, John C wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>Hi all</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>Can anybody help me with the following query?</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>I have a table like:</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><b><u><span style='font-family:"Arial","sans-serif";color:blue'>ItemID Name Number</span></u></b><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>234 Washer 100</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>234 Washer 120</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>234 Washer 105</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>500 Nut 520</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>500 Nut 502</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>500 Nut 501</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></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.</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>My sql is like:</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><b><span style='font-family:"Arial","sans-serif";color:blue'>SELECT *</span></b><o:p></o:p></p><p class=MsoNormal><b><span style='font-family:"Arial","sans-serif";color:blue'>FROM Table</span></b><o:p></o:p></p><p class=MsoNormal><b><span style='font-family:"Arial","sans-serif";color:blue'>GROUP BY ItemID</span></b><o:p></o:p></p><p class=MsoNormal><b><span style='font-family:"Arial","sans-serif";color:blue'>ORDER BY Name, Number</span></b><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>What returns is:</span><o:p></o:p></p><p class=MsoNormal><b><u><span style='font-family:"Arial","sans-serif";color:blue'>ItemID Name Number</span></u></b><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>234 Washer 105</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>500 Nut 501</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></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?</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>Thanks a lot for any help.</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:blue'>John C</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br><br><br><o:p></o:p></span></p><pre>_______________________________________________<o:p></o:p></pre><pre>NZ Borland Developers Group - Delphi mailing list<o:p></o:p></pre><pre>Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><o:p></o:p></pre><pre>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a><o:p></o:p></pre><pre>Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<o:p></o:p></pre></blockquote><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p></div></body></html>