<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Selecting min value in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602191#M270372</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;      group by only f1 to get correct output&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     select f1 MIN( distinct f2) as f2&lt;/P&gt;&lt;P&gt;     into corresponding fields of table itab&lt;/P&gt;&lt;P&gt;     from db1&lt;/P&gt;&lt;P&gt;     where f1 in r_f1&lt;/P&gt;&lt;P&gt;     and f3 = &amp;lt;constant&amp;gt;&lt;/P&gt;&lt;P&gt;     group by f1 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;amole&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Oct 2006 15:13:11 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-10-02T15:13:11Z</dc:date>
    <item>
      <title>Selecting min value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602187#M270368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I coded a select stmt which should return a min value and it is not returning correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  select  f1 MIN( distinct f2) as f2&lt;/P&gt;&lt;P&gt;  f3 f4&lt;/P&gt;&lt;P&gt;  into corresponding fields of table itab&lt;/P&gt;&lt;P&gt;  from  db1&lt;/P&gt;&lt;P&gt;  where f1 in r_f1&lt;/P&gt;&lt;P&gt;  and f3 = &amp;lt;constant&amp;gt;&lt;/P&gt;&lt;P&gt;  group by f1 f3 f4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are 3 rows with f2 = 1, 2 ,3 in the databse table for same f1. I am expecting it would return &amp;lt;b&amp;gt;only&amp;lt;/b&amp;gt; the row with f2 = 1. But this select stmt is getting all the 3 rows into the internal table. Can somebody help me figure out what I did wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Anu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 14:45:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602187#M270368</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T14:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting min value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602188#M270369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Anupama,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select f1 &amp;lt;b&amp;gt;DISTINCT( MIN( f2) )&amp;lt;/b&amp;gt; as f2&lt;/P&gt;&lt;P&gt;f3 f4&lt;/P&gt;&lt;P&gt;into corresponding fields of table itab&lt;/P&gt;&lt;P&gt;from db1&lt;/P&gt;&lt;P&gt;where f1 in r_f1&lt;/P&gt;&lt;P&gt;and f3 = &amp;lt;constant&amp;gt;&lt;/P&gt;&lt;P&gt;group by f1 f3 f4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vinay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 14:53:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602188#M270369</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T14:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting min value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602189#M270370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Anu&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your code will return one row for each line that satisfies your Where clause and is unique to all other lines in the set.  since f2 contains values 1,2 and 3 you will get 1 row for each (so long as there is a row with these values that has the correct values of f1 and f3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it would be far simpler to do the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT f1 f2 f3 f4
INTO CORRESPONDING FIELDS OF TABLE itab
FROM db1
WHERE f1 IN r_f1
AND f3 = &amp;lt;constant&amp;gt;.

SORT itab BY f1 f3 f4 f2 DESCENDING 
DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f3 f4.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've not tested this but it should leave you with one line containing the minimum of f2 and grouped by f1 f3 and f4.  It will also be a more efficient Select as the internal optimiser will be able to work (aggregate functions and Group by etc prevent this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, just changed the sort order!&lt;/P&gt;&lt;P&gt;Message was edited by: Andrew Wright&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 14:58:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602189#M270370</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T14:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting min value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602190#M270371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are getting 3 rows because, there may be 3 different values for F4 in the table. Remove the field from selection or use delete adjacent as mentioned above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sridhar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 15:08:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602190#M270371</guid>
      <dc:creator>sridhar_k1</dc:creator>
      <dc:date>2006-10-02T15:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting min value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602191#M270372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;      group by only f1 to get correct output&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     select f1 MIN( distinct f2) as f2&lt;/P&gt;&lt;P&gt;     into corresponding fields of table itab&lt;/P&gt;&lt;P&gt;     from db1&lt;/P&gt;&lt;P&gt;     where f1 in r_f1&lt;/P&gt;&lt;P&gt;     and f3 = &amp;lt;constant&amp;gt;&lt;/P&gt;&lt;P&gt;     group by f1 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;amole&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 15:13:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602191#M270372</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T15:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting min value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602192#M270373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Andrew. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually I coded this way at first, but then thought I am re-inventing the wheel, why not let select stmt do it for me and then changed the code. But now I realise why it will not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Anu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 15:14:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/selecting-min-value/m-p/1602192#M270373</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T15:14:31Z</dc:date>
    </item>
  </channel>
</rss>

