<?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 with mulitple joins in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686486#M1450383</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;You would need to create dictionary view to join table2 and table3.&lt;/P&gt;&lt;P&gt;The reason for that is you cannot have a join on the right side of other join - see documentation at [http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]. Only db table or view is allowed on the right side.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so your scenario:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;table1 left outer join (table2 join table3)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; is not possible directly in Open SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming you create view which joins table2 and table3 and call it zview1 you can do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;table1 left outer join zview1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. I'm also assuming that you want the data not just count(*) as this would be equal to count of records in table1 fro this query&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Mar 2010 23:25:03 GMT</pubDate>
    <dc:creator>former_member182670</dc:creator>
    <dc:date>2010-03-15T23:25:03Z</dc:date>
    <item>
      <title>Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686480#M1450377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I not able to do a select statement invloving 3 tables and would much appreciate if you'll can help me get it working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
select count(*) from table1 as a
   left join table2 as b on a~field1 = b~field1 
  join table3 on b~field2 = c~field2
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All tables are custom tables. table1 is the item master data and field1 is its primary key.&lt;/P&gt;&lt;P&gt;table2 holds item status field1 and field2 combined form the unique key for this table. Not all items have status so I am doing a left join on table1 and table2.&lt;/P&gt;&lt;P&gt;table2 holds the text for different status, so a join between table2 and table3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My ultimate aim is to bring all items from table1 for a particular criteria and status text (from table3) for items having status. &lt;/P&gt;&lt;P&gt;But the select statement above brings only items having records in table2 (that is records with valid status) i.e. it is treating the left join between table1 and table2 as an inner join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please suggest me the correct order of select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;CD&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Mar 15, 2010 10:16 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 13:17:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686480#M1450377</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-15T13:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686481#M1450378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please list your exact WHERE-conditions here. Since you are selecting by status text in table3, I think it makes sense that the result set contains only rows with a corresponding entry in table2, since table2 and table3 are connected via inner join, so you probably need two selects (or some OR condition) to obtain the final result.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 13:24:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686481#M1450378</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-03-15T13:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686482#M1450379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i would like to have separate internal tables first joining table 1 and table 2 , table 2 and table 3 and merge into final internal table . Use a describe statement to check the count. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//join table3 on b&lt;SUB&gt;field2 = c&lt;/SUB&gt;field2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there should be one link between table 1 and table 3 ?&lt;/P&gt;&lt;P&gt;--&amp;gt;check  join table1 and table3 on what key field to remove the table field .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// select count(*) from table1 as a &lt;STRONG&gt;inner&lt;/STRONG&gt;  join table2 as b on a&lt;SUB&gt;field1 = b&lt;/SUB&gt;field1 &lt;/P&gt;&lt;P&gt;                                          join table3 on b&lt;SUB&gt;field2 = c&lt;/SUB&gt;field2 " &amp;lt;----link to table 1 in here &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;br, &lt;/P&gt;&lt;P&gt;vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 13:24:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686482#M1450379</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-15T13:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686483#M1450380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply, only where condition I have is on created date field in table1 and that does not seem to have an impact on the select behavior as tried removing it..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 13:27:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686483#M1450380</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-15T13:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686484#M1450381</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;As mentioned by you, I derived the structure of three tables as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ZTable1&lt;/P&gt;&lt;P&gt;Item&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ZTable12&lt;/P&gt;&lt;P&gt;Item&lt;/P&gt;&lt;P&gt;Status_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ZTable3&lt;/P&gt;&lt;P&gt;Status_ID&lt;/P&gt;&lt;P&gt;Status_Text&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on this, your select statement should be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select a&lt;SUB&gt;Item c&lt;/SUB&gt;Status_Text&lt;/P&gt;&lt;P&gt;into table itab&lt;/P&gt;&lt;P&gt;from ( ( ZTable1 AS a INNER JOIN ZTable2 AS b&lt;/P&gt;&lt;P&gt;on a&lt;SUB&gt;Item = b&lt;/SUB&gt;Item )&lt;/P&gt;&lt;P&gt;inner join ZTable3 as c on b&lt;SUB&gt;Item_ID = c&lt;/SUB&gt;Item_ID )&lt;/P&gt;&lt;P&gt;Where a~Date in/= .....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ni3&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 14:32:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686484#M1450381</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-15T14:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686485#M1450382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I dont want to do inner join between Table1 and Table2, reason being not all items contained in Table1 are contained in Table2&lt;/P&gt;&lt;P&gt;While the select should retrieve all items regardless they have status (i.e. they are contained in Table2 or not)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 14:44:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686485#M1450382</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-15T14:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686486#M1450383</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;You would need to create dictionary view to join table2 and table3.&lt;/P&gt;&lt;P&gt;The reason for that is you cannot have a join on the right side of other join - see documentation at [http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]. Only db table or view is allowed on the right side.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so your scenario:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;table1 left outer join (table2 join table3)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; is not possible directly in Open SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming you create view which joins table2 and table3 and call it zview1 you can do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;table1 left outer join zview1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. I'm also assuming that you want the data not just count(*) as this would be equal to count of records in table1 fro this query&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Mar 2010 23:25:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686486#M1450383</guid>
      <dc:creator>former_member182670</dc:creator>
      <dc:date>2010-03-15T23:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686487#M1450384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HIIIIIIIIIII CD CHECK THIS CODE AND MODIFY AS PE UR FIELDS OF SELECTION MAY THIS USEFUL FOR YOU&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE Text-001.&lt;/P&gt;&lt;P&gt;PARAMETERS P_BUKRS LIKE BSID-BUKRS DEFAULT '0010'.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS:  S_KTOKD FOR KNA1-KTOKD MEMORY ID KGD,&lt;/P&gt;&lt;P&gt;                 S_KUNNR FOR KNA1-KUNNR,&lt;/P&gt;&lt;P&gt;                 S_BLDAT FOR BSID-BLDAT.&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN END OF BLOCK B1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt; SELECT A&lt;SUB&gt;KUNNR A&lt;/SUB&gt;NAME1 A&lt;SUB&gt;KTOKD B&lt;/SUB&gt;AUGBL B&lt;SUB&gt;XBLNR B&lt;/SUB&gt;ZUONR&lt;/P&gt;&lt;P&gt;         B&lt;SUB&gt;BLDAT B&lt;/SUB&gt;BLART B&lt;SUB&gt;BUDAT B&lt;/SUB&gt;SHKZG B&lt;SUB&gt;BELNR B&lt;/SUB&gt;DMBTR B~SGTXT&lt;/P&gt;&lt;P&gt;         INTO CORRESPONDING FIELDS OF TABLE IDATA&lt;/P&gt;&lt;P&gt;         FROM KNA1 AS A INNER JOIN BSID AS B&lt;/P&gt;&lt;P&gt;         ON B&lt;SUB&gt;KUNNR EQ A&lt;/SUB&gt;KUNNR&lt;/P&gt;&lt;P&gt;                        INNER JOIN BKPF AS C&lt;/P&gt;&lt;P&gt;             ON C&lt;SUB&gt;BUKRS EQ B&lt;/SUB&gt;BUKRS AND&lt;/P&gt;&lt;P&gt;                C&lt;SUB&gt;BELNR EQ B&lt;/SUB&gt;BELNR AND&lt;/P&gt;&lt;P&gt;                C&lt;SUB&gt;GJAHR EQ B&lt;/SUB&gt;GJAHR&lt;/P&gt;&lt;P&gt;          WHERE A~KUNNR IN S_KUNNR AND&lt;/P&gt;&lt;P&gt;                A~KTOKD IN S_KTOKD AND&lt;/P&gt;&lt;P&gt;                B~BUKRS EQ P_BUKRS AND&lt;/P&gt;&lt;P&gt;                B~BLART NE 'DR'    AND&lt;/P&gt;&lt;P&gt;                B~BLDAT IN S_BLDAT .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: pranay panchbhai on Mar 16, 2010 1:45 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Mar 2010 08:15:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686487#M1450384</guid>
      <dc:creator>Pranay_Panchbha</dc:creator>
      <dc:date>2010-03-16T08:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement with mulitple joins</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686488#M1450385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks TMackowski  for the reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes view is one option, I endend up using an internal table for table3 as it has very few records, and I in the program I am anyhow looping through the result set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Mar 2010 15:43:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-with-mulitple-joins/m-p/6686488#M1450385</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-16T15:43:06Z</dc:date>
    </item>
  </channel>
</rss>

