<?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: SELECT statement comparing 2 fields in a table. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985098#M72822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tables likp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data itab type standard table of likp.&lt;/P&gt;&lt;P&gt;select * from likp as l into table itab where vkorg = l~werks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 Jun 2005 09:13:40 GMT</pubDate>
    <dc:creator>jayanthi_jayaraman</dc:creator>
    <dc:date>2005-06-30T09:13:40Z</dc:date>
    <item>
      <title>SELECT statement comparing 2 fields in a table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985096#M72820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone help me out  in making a efficient SELECT statement for the follwing requirement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Say, I want to select all the records from a database table where the field, PLANT is equal to field SALESORG in the table (i.e., when both fields are equal select that record).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;&lt;P&gt;Sree&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2005 09:04:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985096#M72820</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-06-30T09:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT statement comparing 2 fields in a table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985097#M72821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from t001w&lt;/P&gt;&lt;P&gt;         into i_t001w &lt;/P&gt;&lt;P&gt;         where&lt;/P&gt;&lt;P&gt;         werks IN s_werks(select option).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from tvko&lt;/P&gt;&lt;P&gt;         into i_tvko &lt;/P&gt;&lt;P&gt;         for all entries in i_t001w&lt;/P&gt;&lt;P&gt;         where&lt;/P&gt;&lt;P&gt;         vkorg IN s_vkorg&lt;/P&gt;&lt;P&gt;         AND vkorg = i_t001w-vkorg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can try this out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Judith Jessie Selvi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2005 09:10:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985097#M72821</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-06-30T09:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT statement comparing 2 fields in a table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985098#M72822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tables likp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data itab type standard table of likp.&lt;/P&gt;&lt;P&gt;select * from likp as l into table itab where vkorg = l~werks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2005 09:13:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985098#M72822</guid>
      <dc:creator>jayanthi_jayaraman</dc:creator>
      <dc:date>2005-06-30T09:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT statement comparing 2 fields in a table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985099#M72823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think this is the answer to your question... if you explain a bit more we can formulate a query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subquery &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variants: &lt;/P&gt;&lt;P&gt;1. ( select ) &lt;/P&gt;&lt;P&gt;2. ALL ( select ) &lt;/P&gt;&lt;P&gt;3. ANY ( select ) &lt;/P&gt;&lt;P&gt;4. SOME ( select ) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;A subquery is a SELECT statement select that occurs within a &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPEN CURSOR, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPDATE, or &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE statement &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the WHERE clause or HAVING clause, to check whether data from database tables or views meets certain criteria. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subqueries have a restricted syntax in comparison to the normal SELECT statement: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT result FROM source [WHERE where] [GROUP BY fields]       [HAVING having]. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 1 &lt;/P&gt;&lt;P&gt;( select ) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the subquery returns a single value, you can use any relational operator except LIKE and BETWEEN. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Selecting the flights with the most passengers: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: WA TYPE SFLIGHT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT &lt;/P&gt;&lt;P&gt;    INTO WA &lt;/P&gt;&lt;P&gt;    WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ). &lt;/P&gt;&lt;P&gt;  WRITE: / WA-CARRID, WA-CONNID, WA-FLDATE. &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note &lt;/P&gt;&lt;P&gt;If you use a subquery with a relational operator instead of EXISTS, you may only specify one column in the SELECT clause. This can be either a field from the database table or an aggregate expression. Subqueries of this kind are referred to as scalar subqueries. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 2 &lt;/P&gt;&lt;P&gt;ALL ( select ) &lt;/P&gt;&lt;P&gt;If the subquery returns several lines, each containing one value, you specify that the comparison should apply for all of the values it returns. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;This example shows how to use ALL. It displays a list of the customer IDs of the customer (or customers) who have made the most bookings: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: ID TYPE SBOOK-CUSTOMID, CNT TYPE I. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT CUSTOMID COUNT( * ) AS C FROM SBOOK &lt;/P&gt;&lt;P&gt;    INTO (ID, CNT) &lt;/P&gt;&lt;P&gt;    GROUP BY CUSTOMID &lt;/P&gt;&lt;P&gt;    HAVING COUNT( * ) &amp;gt;= &lt;/P&gt;&lt;P&gt;      ALL ( SELECT COUNT( * ) FROM SBOOK GROUP BY CUSTOMID ). &lt;/P&gt;&lt;P&gt;  WRITE: / ID, CNT. &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 3 &lt;/P&gt;&lt;P&gt;ANY ( select ) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variant 4 &lt;/P&gt;&lt;P&gt;SOME ( select ) &lt;/P&gt;&lt;P&gt;If the subquery returns several lines each containing one value, this variant specifies that the comparison should apply to at least one of the values returned. The IN operator is the same as the combination = ANY. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;ABAP_HINT &lt;/P&gt;&lt;P&gt;If you use a subquery with the EXISTS operator, the expression is true if the subquery selects at least one line. You can useuse * in the SELECT clause of subqueries that use EXISTS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Selecting all flights from Frankfurt to New York between 1.1.1999 and 31.3.1999 that are not yet full: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: WA_SFLIGHT TYPE SFLIGHT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT &lt;/P&gt;&lt;P&gt;    WHERE SEATSOCC &amp;lt; F~SEATSMAX &lt;/P&gt;&lt;P&gt;      AND EXISTS ( SELECT * FROM SPFLI &lt;/P&gt;&lt;P&gt;                    WHERE CARRID = F~CARRID &lt;/P&gt;&lt;P&gt;                       AND CONNID = F~CONNID &lt;/P&gt;&lt;P&gt;                       AND CITYFROM = 'FRANKFURT' &lt;/P&gt;&lt;P&gt;                       AND CITYTO = 'NEW YORK' ) &lt;/P&gt;&lt;P&gt;      AND FLDATE BETWEEN '19990101' AND '19990331'. &lt;/P&gt;&lt;P&gt;  WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID, &lt;/P&gt;&lt;P&gt;           WA_SFLIGHT-FLDATE. &lt;/P&gt;&lt;P&gt;ENDSELECT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subqueries such as the one in this example, in which the WHERE clause uses fields from the main query, are known as correlated subqueries. Subqueries can be nested, and a given subquery may contain any fields from other, hierarchically-superior subqueries. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a correlated subquery, the subquery is executed for each line r returned by the main query. In the above example, the main query finds all flights in table SFLIGHT that are not full and that have a date that meets the selection criterion. The statement then performs the subquery for each of the records returned by the main query, using the corresponding values of CARRID and CONNID, to check whether the relevant flight operates between Frankfurt and New York. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additional help &lt;/P&gt;&lt;P&gt;Subqueries&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2005 09:19:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985099#M72823</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-06-30T09:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT statement comparing 2 fields in a table.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985100#M72824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jayanthi! this is what exactly I was looking for &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Shekar &amp;amp; Judith for your sugesstions!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sree&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2005 09:41:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-comparing-2-fields-in-a-table/m-p/985100#M72824</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-06-30T09:41:55Z</dc:date>
    </item>
  </channel>
</rss>

