<?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: Basic SQL question in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273567#M1988099</link>
    <description>&lt;P&gt;Please format your code with the button CODE.&lt;/P&gt;&lt;P&gt;Something like this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT CARRID, CONNID, FLDATE
  FROM SFLIGHT AS A
  WHERE EXISTS (
         SELECT B~CARRID FROM SFLIGHT AS B
         WHERE A~CARRID = B~CARRID
           AND A~CONNID = B~CONNID
         GROUP BY B~CARRID
         HAVING A~FLDATE = MAX( B~FLDATE ) )
  INTO TABLE @DATA(SFLIGHT_LINES).&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 Jul 2020 09:36:13 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2020-07-27T09:36:13Z</dc:date>
    <item>
      <title>Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273565#M1988097</link>
      <description>&lt;P&gt;Hi, all&lt;/P&gt;
  &lt;P&gt;I have a table with following fields:&lt;BR /&gt;&lt;BR /&gt;FIELD1 KEY&lt;BR /&gt;FIELD2 KEY &lt;BR /&gt;FIELD3 (no key but secondary key exists)&lt;BR /&gt;DATE&lt;BR /&gt;TIME&lt;BR /&gt;&lt;BR /&gt;I would like to select all the records with last date and time grouping only by FIELD2.&lt;BR /&gt;&lt;BR /&gt;I'm trying the following:&lt;/P&gt;
  &lt;BR /&gt;
  &lt;PRE&gt;&lt;CODE&gt;SELECT FIELD1 FIELD2 FIELD3 MAX( DATA ) MAX( TIME )&lt;BR /&gt;FROM MY_TABLE&lt;BR /&gt;WHERE FIELD3 EQ 'TEST'&lt;BR /&gt;GROUP BY FIELD2.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I have the following sintax error: &lt;/P&gt;
  &lt;P&gt;The field "FIELD1" from the SELECT list is is missing in the GROUP BY clause.&lt;BR /&gt;&lt;BR /&gt;But I dont want to group by FIELD1, because can have different values for each FIELD2. I only want to get all the colums for each FIELD2 that have the max date and time.&lt;BR /&gt;&lt;BR /&gt;Is it possible with a single select?&lt;BR /&gt;&lt;BR /&gt;ABAP: 731&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 09:06:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273565#M1988097</guid>
      <dc:creator>oliver_am</dc:creator>
      <dc:date>2020-07-27T09:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273566#M1988098</link>
      <description>&lt;P&gt;why do you specify columns FIELD1, FIELD3  if you only want FIELD2 ?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 09:08:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273566#M1988098</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2020-07-27T09:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273567#M1988099</link>
      <description>&lt;P&gt;Please format your code with the button CODE.&lt;/P&gt;&lt;P&gt;Something like this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT CARRID, CONNID, FLDATE
  FROM SFLIGHT AS A
  WHERE EXISTS (
         SELECT B~CARRID FROM SFLIGHT AS B
         WHERE A~CARRID = B~CARRID
           AND A~CONNID = B~CONNID
         GROUP BY B~CARRID
         HAVING A~FLDATE = MAX( B~FLDATE ) )
  INTO TABLE @DATA(SFLIGHT_LINES).&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jul 2020 09:36:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273567#M1988099</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-07-27T09:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273568#M1988100</link>
      <description>&lt;UL&gt;&lt;LI&gt;GROUP BY will only select distinct value combinations of all attributes in the group by clause. Those attributes have to be part of the select clause and no aggregation (sum, max, average, ...) can be applied to those. &lt;BR /&gt;All other attributes in the select clause have to be part of an aggregation function (sum, max, average, ...)&lt;BR /&gt;If you only want to have distinct values for field2, all other selected attributes need to have an aggregation function. If an aggregation is not desired or not possible, those attributes (e.g. field1, field3) cannot be part of the select clause&lt;/LI&gt;&lt;LI&gt;Getting the latest timestamp for a field2 value:&lt;BR /&gt;Using the aggregation max(date) and max(time) seems to make little sense to me, as of right now. This will give you the field2 value with the latest date which I understand, but it will give you also the latest time of any date, which I dont understand. Most likely, you are trying to get the latest date+time of a field2 value, correct? But because two attributes are used for date and time, instead of one (e.g. timestamp), you need a slightly different approach.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 27 Jul 2020 10:05:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273568#M1988100</guid>
      <dc:creator>michael_piesche</dc:creator>
      <dc:date>2020-07-27T10:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273569#M1988101</link>
      <description>&lt;P&gt;Thanks Sandra. I think this is what I need.&lt;BR /&gt;Freederic, I want all the columns, but only group by FIELD2&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 10:22:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273569#M1988101</guid>
      <dc:creator>oliver_am</dc:creator>
      <dc:date>2020-07-27T10:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273570#M1988102</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;oliver.am&lt;/SPAN&gt;, so I think the solution of  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;  is the good one.&lt;/P&gt;&lt;P&gt;First select to get all the key needed, second, get the final result.&lt;/P&gt;&lt;P&gt;But, what would be the result if you have &lt;/P&gt;&lt;P&gt;Field1    Field2    Date&lt;/P&gt;&lt;P&gt;A           A       01.01.2010&lt;/P&gt;&lt;P&gt;B          A        02.01.2010&lt;/P&gt;&lt;P&gt;C          A         02.01.2010&lt;/P&gt;&lt;P&gt;Because first select give  Field 2: A     Date: 02.01.2010 &lt;/P&gt;&lt;P&gt;But field1 will have two possible values&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 10:43:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273570#M1988102</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2020-07-27T10:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273571#M1988103</link>
      <description>&lt;P&gt;Hi, Frederic.&lt;BR /&gt;That's a good question, I guess depends on the order of the rows. &lt;BR /&gt;I'll check with functional team what we need to do in this case.&lt;/P&gt;&lt;P&gt;MAX is returning only one of these rows? or both with the MAX value?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 14:05:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273571#M1988103</guid>
      <dc:creator>oliver_am</dc:creator>
      <dc:date>2020-07-27T14:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Basic SQL question</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273572#M1988104</link>
      <description>&lt;P&gt;If you want to target someone, if this person has posted an Answer, use the button REPLY, if this person is the Original Poster of the question he/she will be automatically informed, otherwise copy/paste their hyperlinked name so that the person receives a warning (NB: @ doesn't work/but typing this character will suggest hyperlinked names).&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 18:15:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/basic-sql-question/m-p/12273572#M1988104</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-07-27T18:15:44Z</dc:date>
    </item>
  </channel>
</rss>

