Multiple inner joins

any ideas on the following? not sure how to end the query..
select route.COLLECTIONFROM, schedule.DEPARTURE, route.deliveryto, schedule.arrival, goods.goodscontent, consignment.weight
from route, schedule, goods, consignment
where route.routeid=schedule.routeid, consignment.consignmentid=route.consignmentid, goods.consignmentid=consignment.consignmentid
gives this error:
Error starting at line 1 in command:
select route.COLLECTIONFROM, schedule.DEPARTURE, route.deliveryto, schedule.arrival, goods.goodscontent, consignment.weight
from route, schedule, goods, consignment
where route.routeid=schedule.routeid, consignment.consignmentid=route.consignmentid, goods.consignmentid=consignment.consignmentid
Error at Command Line:3 Column:36
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:   
*Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

hmmm..placing AND in between:
Error starting at line 1 in command:
select route.COLLECTIONFROM, schedule.DEPARTURE, route.deliveryto, schedule.arrival, goods.goodscontent, consignment.weight
from route, schedule, goods, consignment
where route.routeid=schedule.routeid AND consignment.consignmentid=route.consignmentid AND goods.consignmentid=consignment.consignmentid
Error at Command Line:3 Column:91
Error report:
SQL Error: ORA-00904: "GOODS"."CONSIGNMENTID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:   
*Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Multiple inner joins combined with outer and right.

    Hello
    Can someone give me an example of multiple inner joins?
    Meaning inner join on more than 3 tables. Can someone provide me sql statement that would be great?
    Also can you combine inner outer and right in one query if so how? Again, can someone provide me sql statement that would be great?
    Thank you so much

    You can look at my sample Re: Need Assistance to write a procedure for the below requirements!!!
    John

  • Multiple inner join ..how they work ?

    Here is an example of INNER JOIN.
    SELECT whatever
      FROM tablea AS a
    INNER
      JOIN tableb AS b
        ON b.b = a.a
    INNER
      JOIN tablec AS c
        ON c.c = b.b1
    INNER
      JOIN tabled AS d
        ON d.d = c.c1As you see there are 3 inner join in a single query ...I'm uncomfortable with this ....because I dont know what is the order of execution of multiple inner joins .
    which inner join will be executed first and which is next and which is last ?

    Hi,
    user575089 wrote:
    but you know my concern is .... is not the result of inner join is fed to the next inner join ? ( because there is multiple inner join )Sorry, I don't know what your concern is. Try to explain it, prefereably with a concrete example. Post a specific query, using the dept, emp and salgrade tables in the scott schema (or 3 tables for which you post CREATE TABLE and INSERT statements), and a specific question about that query. If you really need 4 tables to show what your problem is, you can use the hr schama instead of scott.Is it possible to test using MySQL ? What happens when you try it?
    I know its an oracle forum You're right; this is an Oracle forum.
    ....that should not be a problem I guess... ..coz SQL is a universal language ...The English language spoken in Britain is different from the English language spoken in the United States. The differences are minor compared to, say, the differences between either and Hindi, but there are differences.
    The SQL langauge used in Oracle is different from the SQL language used in MySQL, even more that the English language used in Britain is different from the English language used in the United States.
    I'm guessing that how MySQL and Oracle perform inner joins is pretty similar, as far as it matters for your question, but that's just a guess. I don't know a lot about MySQL, and I don't know what your question is.

  • PROB INNER JOIN

    BELOW IS MY PROGRAM. AND I WANT TO SHOW THE WHOLE DATA OF ALL THE TABLE.SO HOW I WILL DEFINE TABLE IN DATA STATEMENT AND IN SELECT STATEMENT.
    PLZ IT'S URGENT
    TAHNKS..
    SAM
    *& Report  ZTEMP_JOIN
    REPORT  ZTEMP_JOIN.
    TABLES: MARA,MARC,MARD,MSEG, MAST.
    SELECT-OPTIONS: SAM FOR MARA-MATNR.
    DATA: BEGIN OF ITAB OCCURS 0,
          MATNR LIKE MARA-MATNR,
          ERSDA LIKE MARA-ERSDA,
          ERNAM LIKE MARA-ERNAM,
          MTART LIKE MARA-MTART,
          WERKS LIKE MARC-WERKS,
          PSTAT LIKE MARC-PSTAT,
          LVORM LIKE MARC-LVORM,
          LFGJA LIKE MARD-LFGJA,
          MBLNR LIKE MSEG-MBLNR,
          MJAHR LIKE MSEG-MJAHR,
          BWART LIKE MSEG-BWART,
          STLAN LIKE MAST-STLAN,
          STLAL LIKE MAST-STLAL,
          STLNR LIKE MAST-STLNR,
          END OF ITAB.
    SELECT MA~MATNR MA~ERSDA MA~ERNAM MA~MTART MC~WERKS MC~PSTAT MC~LVORM MD~LFGJA MG~MBLNR MG~MJAHR MG~BWART MT~STLAN MT~STLAL MT~STLNR
           INTO TABLE ITAB FROM MARA AS MA INNER JOIN MARC AS MC ON
           MA~MATNR = MC~MATNR
           INNER JOIN MARD AS MD ON
           MC~MATNR = MD~MATNR
           INNER JOIN MSEG AS MG ON
           MD~MATNR = MG~MATNR
           INNER JOIN MAST AS MT ON
           MG~MATNR = MT~MATNR
           WHERE MA~MATNR IN SAM.
    LOOP AT ITAB.
      WRITE:/ ITAB-MATNR,ITAB-ERSDA,ITAB-ERNAM,ITAB-MTART,ITAB-WERKS, ITAB-PSTAT, ITAB-LVORM, ITAB-LFGJA,
              ITAB-MBLNR, ITAB-MJAHR, ITAB-BWART, ITAB-STLAN, ITAB-STLAL, ITAB-STLNR.
    ENDLOOP.
    *START-OF-SELECTION.
    WRITE: / 'line 1'.
    WRITE: / 'line 2'.
    WRITE: / 'line 3'.
    TOP-OF-PAGE.
      WRITE: / 'MM FIVE TABLES INNNER JOIN'.
      ULINE.
    TOP-OF-PAGE.
      WRITE: /1(109) sy-uline.
      WRITE: /1 '|', 2(18)  'MATNR-MATNR' COLOR 1,
             20 '|', 21(8)  'ERSDA' COLOR 2,
             29 '|', 30(12) 'ERNAM-ERNAM' COLOR 3,
             42 '|', 43(4)  'MTART' COLOR 4,
             47 '|', 48(4)  'WERKS' COLOR 5,
             52 '|', 53(15) 'PSTAT-PSTAT' COLOR 6,
             68 '|', 69(1)  'LVORM' COLOR 7,
             70 '|', 71(4)  'LFGJA' COLOR 1,
             75 '|', 76(10) 'MBLNR' COLOR 2,
             86 '|', 87(4)  'MJAHR' COLOR 3,
             91 '|', 92(3)  'BWART' COLOR 4,
             95 '|', 96(1)  'STLAN' COLOR 5,
             97 '|', 98(2)  'STLAL' COLOR 6,
            100 '|', 101(8) 'STLNR' COLOR 7,
            109 '|'.
      WRITE: /1(109) sy-uline.

    Hi Sam,
    Refer sample code when using Multiple INNER JOIN.
    SELECT T1~PERNR
             T7~ZDSILONR
             T7~ZDTEAMNR
             T1~AUFNR
             T1~GMNGA
             T2~MATNR
             T2~CHARG
             T4~ARBPL
             T8~AUART
           INTO  TABLE I_ITAB1
             FROM  ( ( ( ( AFRU AS T1 INNER JOIN AFPO AS T2
                           ON T1WERKS = T2DWERK AND
                              T1AUFNR = T2AUFNR )
                     INNER JOIN S022 AS T4 ON T4AUFNR = T1AUFNR AND
                                               T4~VORNR = C_VORNR )
            INNER JOIN ZTK_ORDRSILOTEAM AS T7 ON T7ZDAUFNR = T1AUFNR )
                   INNER JOIN AUFK AS T8 ON T8AUFNR = T2AUFNR  )
                       WHERE T1~WERKS IN S_PLANT   AND
                               T1~BUDAT IN S_START   AND
                               T1~PERNR IN S_SHIFT   AND
                               T7~ZDTEAMNR IN S_TEAM AND
                               T2~MATNR IN S_ITEM    AND
                               T1AUFNR = T8AUFNR   AND
                               T4~ARBPL IN S_WORK    AND
                               T8~AUART IN (C_ZCES,C_ZCRS,C_ZCEX,
                                            C_ZCFT,C_ZCFS,C_ZCFX).
    Reward points if this Helps.
    Manish

  • Coupling  INNER  JOIN   with   FOR  ALL  ENTRIES  statement

    Hi  All,
         I   am  coupling   INNER  JOIN  with  FOR  ALL  ENTRIES  statement  .....
         Would   you  please  highlight  its  implications ??   Is  it  a  best  practise ? 
         Is  it  advicable  to  use  MULTIPLE   INNER  JOINs  with  a  FOR  ALL  ENTRIES ???
        SORT itab BY matnr.
        IF NOT itab[] IS INITIAL.
          SELECT       epmatnr epebeln ep~ebelp
                       epwerks epmenge ep~netpr
                       ekps_psp_pnr ebbelnr eb~menge
                       INTO TABLE iekpo
                       FROM ekpo AS ep
                       INNER JOIN ekkn AS ek
                       ON  ekebeln = epebeln
                       AND ekebelp = epebelp
                       INNER JOIN ekbe AS eb
                       ON     ebebeln = epebeln
                       AND    ebebelp = epebelp
                       AND    eb~bwart = '101'
                       FOR ALL  ENTRIES IN itab
                       WHERE   ep~matnr = itab-matnr.
          IF sy-subrc EQ 0.
            SORT iekpo BY matnr werks.
            LOOP  AT  itab ASSIGNING  <itab>.
              READ TABLE iekpo WITH KEY matnr = <itab>-matnr
                                        werks = <itab>-werks
                                        BINARY SEARCH.
              IF sy-subrc EQ 0.
                MOVE iekpo-matnr      TO   itab1-matnr.
                MOVE iekpo-ebeln      TO   itab1-ebeln.
                MOVE iekpo-ebelp      TO   itab1-ebelp.
                MOVE iekpo-netpr      TO   itab1-poprice.
                MOVE iekpo-werks      TO   itab1-werks.
                MOVE iekpo-menge      TO   itab1-menge1.
                MOVE iekpo-menge1     TO   itab1-menge2.
                MOVE iekpo-belnr      TO   itab1-belnr.
                MOVE iekpo-ps_psp_pnr TO   itab1-pspel.
                MOVE <itab>-pspel     TO   itab1-tpspel.
                MOVE <itab>-sobkz     TO   itab1-sobkz.
                MOVE <itab>-fo_qty    TO   itab1-fo_qty.
                MOVE <itab>-schgt     TO   itab1-schgt.
                MOVE <itab>-postp     TO   itab1-postp.
                MOVE <itab>-beskz     TO   itab1-beskz.
                pend_qty = iekpo-menge1 - iekpo-menge2.
                MOVE pend_qty         TO   itab1-pending.
                APPEND itab1.
                pend_qty = 0.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
      ENDIF.
    Regards
    Jaman
    Edited by: ABAP Techie on Sep 15, 2008 12:39 PM
    Edited by: ABAP Techie on Sep 15, 2008 12:41 PM

    best practise ... don't know ... it is allowed and o.k.
    If possible you should of coourse to have no FOR ALL ENTRIES at all !
    Joins, there is no general rule, check indexes etc.
    The first SORT, I don't that it help for anything, use it together with the delete adjacent duplicates if you expect duplicates in the driver table.
    o.k., it can help, if there is a loop afterwards and an append inside, because the new table itab1 is then sorted.
    Siegfried

  • How to use Inner join of table as Source in Merge statement in SQL

    Hi All,
        I am trying to make source as multiple tables output using Join while coding there is no any syntax error but when i am executing this statement is giving following error
    Following is the query 
    Merge Into EmpDept Target
    Using (select E.Address,e.Design,e.EmailId,e.EmpId,e.Ename,e.ManagerId, e.Salary,D.DeptId,D.DeptName,D.Location from Employee E Inner join Dept D on E.DeptId=D.DeptId )As Source (Address,Design,EmailId,EmpId,EName,ManagerId,Salary,DeptId,DeptName,Location)
    On Source.EmpId=Target.EmpId
    when not matched then
    Insert (Target.Address,Target.Design,Target.EmailId,Target.EmpId,Target.Ename,Target.ManagerId, Target.Salary,Target.DeptId,Target.DeptName,Target.Location)
    values
    (Address,Design,EmailId,EmpId,EName,ManagerId, Salary,DeptId,DeptName,Location)
    When matched then 
    Update set Target.Address = Source.Address ,Target.Design = Source.Design,Target.EmailId      = Source.EmailId     ,Target.Ename       = Source.Ename      ,Target.ManagerId = Source.ManagerId , Target.Salary        = Source.Salary       ,Target.DeptId      = Source.DeptId      ,Target.DeptName = Source.DeptName ,Target.Location    = Source.Location;
    This is error while executing the above merge statement 
    The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.
    Please suggest me where i am wrong.. 
    Niraj Sevalkar

    MERGE INTO EmpDept Target
    Using (SELECT E.Address,
    e.Design,
    e.EmailId,
    e.EmpId,
    e.Ename,
    e.ManagerId,
    e.Salary,
    D.DeptId,
    D.DeptName,
    D.Location
    FROM Employee E
    INNER JOIN Dept D
    ON E.DeptId = D.DeptId) AS Source (Address, Design, EmailId, EmpId, EName, ManagerId, Salary, DeptId, DeptName, Location)
    ON Source.EmpId = Target.EmpId
    WHEN NOT matched THEN
    INSERT (Address,
    Design,
    EmailId,
    EmpId,
    Ename,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    VALUES (Address,
    Design,
    EmailId,
    EmpId,
    EName,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    WHEN matched THEN
    UPDATE SET Address = Source.Address,
    Design = Source.Design,
    EmailId = Source.EmailId,
    Ename = Source.Ename,
    ManagerId = Source.ManagerId,
    Salary = Source.Salary,
    DeptId = Source.DeptId,
    DeptName = Source.DeptName,
    Location = Source.Location;

  • Problem with a query inner-join

    Hello;
    I'm trying to innerjoin these 2 tables in my query for a page that will allow you to add / edit records. Right now, it's telling me I have a data mismatch. I don't see where I went wrong. Can someone help me out?
    This is my code:
    <cfparam name="url.CategoryID" type="integer" default="0">
    <cfparam name="subID" type="integer" default="#url.CategoryID#">
    <cfparam name="subName" default="">
    <cfparam name="CategoryID" default="">
    <cfparam name="Name" default="">
    <cfif url.CategoryID GT 0>
    <cfquery name="categRec" dataSource="#APPLICATION.dataSource#">
    SELECT merchSubCat.subName, merchSubCat.subID, Categories.CategoryID, Categories.Name
    FROM merchSubCat
    INNER JOIN Categories
        ON merchSubCat.CategoryID = Categories.CategoryID
    WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_integer">
    </cfquery>
    <!--- if the record was found, store the values --->
    <cfif categRec.RecordCount EQ 1>
    <cfset CategoryID = categRec.subID>
    <cfset subName = categRec.subName>
    <cfset CategoryID = categRec.CategoryID>
    <cfset Name = categRec.Name>
    </cfif>
    </cfif>
    this is my error:
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Type mismatch in expression.
    The error occurred in C:\Websites\187914kg3\admin\cms\merchant\merchSub-edit.cfm: line 16
    14 : INNER JOIN Categories
    15 :     ON merchSubCat.CategoryID = Categories.CategoryID
    16 : WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_integer">
    17 : </cfquery>
    18 :
    I don't see what I did wrong, can another pair of eyes see where I missed something?
    Thank you

    I changed it to number, and it works now.
    I have one other problem.. I'm trying to use a drop down menu in this form to edit a record. I want the drop down to show what is being used in the database when you go to edit a record. It runs on one query, to populate the select, but it pulls info from another and this isn't working. Actually, it's the innerjoin I just made.. can you help me?
    <!--- query that runs the select --->
    <cfquery name="catList" datasource="#APPLICATION.dataSource#">
    SELECT DISTINCT merchCategory.CategoryID, merchCategory.CatName AS cat_name
    FROM merchCategory
    ORDER BY CatName
    </cfquery>
    <cfselect enabled="No" name="CategoryID" size="1" class="smallText" multiple="no" query="catList" value="CategoryID" display="cat_name" queryPosition="below" selected="#categRec.Name#">
                      <option value="">--Select a Category--</option>
                  </cfselect>
    As you see, in the selected part of the tag, I'm trying to pull info from the other query we just fixed. I know this is wrong, how do I do this?

  • Query related to inner join V/S all entries........

    Hi all,
    I have a dought ...related to join and all entries
    Which one will be the better as per performance prospective :
    1>For all entries
    or
    2> using inner join condition
    i am combining 2 tables ...
    but in my where clause is having 6-7 condition if i used inner join concept...
    Please let me know thanks for the help...in advance
    regards
    Amit

    Check Re: Multiple Table Join instead of Nested Selects? I wrote a program that compares the performance of a join against for all entries. The join won. But the best thing to do is for you test and compare both methods for your particular situation.
    In a select, the most important factor is the use of an index.
    Rob

  • Very Slow Query with CTE inner join

    I have 2 tables (heavily simplified here to show relevant columns):
    CREATE TABLE tblCharge
    (ChargeID int NOT NULL,
    ParentChargeID int NULL,
    ChargeName varchar(200) NULL)
    CREATE TABLE tblChargeShare
    (ChargeShareID int NOT NULL,
    ChargeID int NOT NULL,
    TotalAmount money NOT NULL,
    TaxAmount money NULL,
    DiscountAmount money NULL,
    CustomerID int NOT NULL,
    ChargeShareStatusID int NOT NULL)
    I have a very basic View to Join them:
    CREATE VIEW vwBASEChargeShareRelation as
    Select c.ChargeID, ParentChargeID, s.CustomerID, s.TotalAmount, isnull(s.TaxAmount, 0) as TaxAmount, isnull(s.DiscountAmount, 0) as DiscountAmount
    from tblCharge c inner join tblChargeShare s
    on c.ChargeID = s.ChargeID Where s.ChargeShareStatusID < 3
    GO
    I then have a view containing a CTE to get the children of the Parent Charge:
    ALTER VIEW [vwChargeShareSubCharges] AS
    WITH RCTE AS
    SELECT ParentChargeId, ChargeID, 1 AS Lvl, ISNULL(TotalAmount, 0) as TotalAmount, ISNULL(TaxAmount, 0) as TaxAmount,
    ISNULL(DiscountAmount, 0) as DiscountAmount, CustomerID, ChargeID as MasterChargeID
    FROM vwBASEChargeShareRelation Where ParentChargeID is NULL
    UNION ALL
    SELECT rh.ParentChargeID, rh.ChargeID, Lvl+1 AS Lvl, ISNULL(rh.TotalAmount, 0), ISNULL(rh.TaxAmount, 0), ISNULL(rh.DiscountAmount, 0) , rh.CustomerID
    , rc.MasterChargeID
    FROM vwBASEChargeShareRelation rh
    INNER JOIN RCTE rc ON rh.PArentChargeID = rc.ChargeID and rh.CustomerID = rc.CustomerID
    Select MasterChargeID as ChargeID, CustomerID, Sum(TotalAmount) as TotalCharged, Sum(TaxAmount) as TotalTax, Sum(DiscountAmount) as TotalDiscount
    from RCTE
    Group by MasterChargeID, CustomerID
    GO
    So far so good, I can query this view and get the total cost for a line item including all children.
    The problem occurs when I join this table. The query:
    Select t.* from vwChargeShareSubCharges t
    inner join
    tblChargeShare s
    on t.CustomerID = s.CustomerID
    and t.MasterChargeID = s.ChargeID
    Where s.ChargeID = 1291094
    Takes around 30 ms to return a result (tblCharge and Charge Share have around 3.5 million records).
    But the query:
    Select t.* from vwChargeShareSubCharges t
    inner join
    tblChargeShare s
    on t.CustomerID = s.CustomerID
    and t.MasterChargeID = s.ChargeID
    Where InvoiceID = 1045854
    Takes around 2 minutes to return a result - even though the only charge with that InvoiceID is the same charge as the one used in the previous query.
    The same thing occurs if I do the join in the same query that the CTE is defined in.
    I ran the execution plan for each query. The first (fast) query looks like this:
    The second(slow) query looks like this:
    I am at a loss, and my skills at decoding execution plans to resolve this are lacking.
    I have separate indexes on tblCharge.ChargeID, tblCharge.ParentChargeID, tblChargeShare.ChargeID, tblChargeShare.InvoiceID, tblChargeShare.ChargeShareStatusID
    Any ideas? Tested on SQL 2008R2 and SQL 2012

    >> The database is linked [sic] to an established app and the column and table names can't be changed. <<
    Link? That is a term from pointer chains and network databases, not SQL. I will guess that means the app came back in the old pre-RDBMS days and you are screwed. 
    >> I am not too worried about the money field [sic], this is used for money and money based calculations so the precision and rounding are acceptable at this level. <<
    Field is a COBOL concept; columns are totally different. MONEY is how Sybase mimics the PICTURE clause that puts currency signs, commas, period, etc in a COBOL money field. 
    Using more than one operation (multiplication or division) on money columns will produce severe rounding errors. A simple way to visualize money arithmetic is to place a ROUND() function calls after 
    every operation. For example,
    Amount = (Portion / total_amt) * gross_amt
    can be rewritten using money arithmetic as:
    Amount = ROUND(ROUND(Portion/total_amt, 4) * 
    gross_amt, 4)
    Rounding to four decimal places might not seem an 
    issue, until the numbers you are using are greater 
    than 10,000. 
    BEGIN
    DECLARE @gross_amt MONEY,
     @total_amt MONEY,
     @my_part MONEY,
     @money_result MONEY,
     @float_result FLOAT,
     @all_floats FLOAT;
     SET @gross_amt = 55294.72;
     SET @total_amt = 7328.75;
     SET @my_part = 1793.33;
     SET @money_result = (@my_part / @total_amt) * 
    @gross_amt;
     SET @float_result = (@my_part / @total_amt) * 
    @gross_amt;
     SET @Retult3 = (CAST(@my_part AS FLOAT)
     / CAST( @total_amt AS FLOAT))
     * CAST(FLOAT, @gross_amt AS FLOAT);
     SELECT @money_result, @float_result, @all_floats;
    END;
    @money_result = 13525.09 -- incorrect
    @float_result = 13525.0885 -- incorrect
    @all_floats = 13530.5038673171 -- correct, with a -
    5.42 error 
    >> The keys are ChargeID(int, identity) and ChargeShareID(int, identity). <<
    Sorry, but IDENTITY is not relational and cannot be a key by definition. But it sure works just like a record number in your old COBOL file system. 
    >> .. these need to be int so that they are assigned by the database and unique. <<
    No, the data type of a key is not determined by physical storage, but by logical design. IDENTITY is the number of a parking space in a garage; a VIN is how you identify the automobile. 
    >> What would you recommend I use as keys? <<
    I do not know. I have no specs and without that, I cannot pull a Kabbalah number from the hardware. Your magic numbers can identify Squids, Automobile or Lady Gaga! I would ask the accounting department how they identify a charge. 
    >> Charge_Share_Status_ID links [sic] to another table which contains the name, formatting [sic] and other information [sic] or a charge share's status, so it is both an Id and a status. <<
    More pointer chains! Formatting? Unh? In RDBMS, we use a tiered architecture. That means display formatting is in a presentation layer. A properly created table has cohesion – it does one and only one data element. A status is a state of being that applies
    to an entity over a period time (think employment, marriage, etc. status if that is too abstract). 
    An identifier is based on the Law of Identity from formal logic “To be is to be something in particular” or “A is A” informally. There is no entity here! The Charge_Share_Status table should have the encoded values for a status and perhaps a description if
    they are unclear. If the list of values is clear, short and static, then use a CHECK() constraint. 
    On a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, this is literally that silly and wrong. 
    >> I understand what a CTE is; is there a better way to sum all children for a parent hierarchy? <<
    There are many ways to represent a tree or hierarchy in SQL.  This is called an adjacency list model and it looks like this:
    CREATE TABLE OrgChart 
    (emp_name CHAR(10) NOT NULL PRIMARY KEY, 
     boss_emp_name CHAR(10) REFERENCES OrgChart(emp_name), 
     salary_amt DECIMAL(6,2) DEFAULT 100.00 NOT NULL,
     << horrible cycle constraints >>);
    OrgChart 
    emp_name  boss_emp_name  salary_amt 
    ==============================
    'Albert'    NULL    1000.00
    'Bert'    'Albert'   900.00
    'Chuck'   'Albert'   900.00
    'Donna'   'Chuck'    800.00
    'Eddie'   'Chuck'    700.00
    'Fred'    'Chuck'    600.00
    This approach will wind up with really ugly code -- CTEs hiding recursive procedures, horrible cycle prevention code, etc.  The root of your problem is not knowing that rows are not records, that SQL uses sets and trying to fake pointer chains with some
    vague, magical non-relational "id".  
    This matches the way we did it in old file systems with pointer chains.  Non-RDBMS programmers are comfortable with it because it looks familiar -- it looks like records and not rows.  
    Another way of representing trees is to show them as nested sets. 
    Since SQL is a set oriented language, this is a better model than the usual adjacency list approach you see in most text books. Let us define a simple OrgChart table like this.
    CREATE TABLE OrgChart 
    (emp_name CHAR(10) NOT NULL PRIMARY KEY, 
     lft INTEGER NOT NULL UNIQUE CHECK (lft > 0), 
     rgt INTEGER NOT NULL UNIQUE CHECK (rgt > 1),
      CONSTRAINT order_okay CHECK (lft < rgt));
    OrgChart 
    emp_name         lft rgt 
    ======================
    'Albert'      1   12 
    'Bert'        2    3 
    'Chuck'       4   11 
    'Donna'       5    6 
    'Eddie'       7    8 
    'Fred'        9   10 
    The (lft, rgt) pairs are like tags in a mark-up language, or parens in algebra, BEGIN-END blocks in Algol-family programming languages, etc. -- they bracket a sub-set.  This is a set-oriented approach to trees in a set-oriented language. 
    The organizational chart would look like this as a directed graph:
                Albert (1, 12)
        Bert (2, 3)    Chuck (4, 11)
                       /    |   \
                     /      |     \
                   /        |       \
                 /          |         \
            Donna (5, 6) Eddie (7, 8) Fred (9, 10)
    The adjacency list table is denormalized in several ways. We are modeling both the Personnel and the Organizational chart in one table. But for the sake of saving space, pretend that the names are job titles and that we have another table which describes the
    Personnel that hold those positions.
    Another problem with the adjacency list model is that the boss_emp_name and employee columns are the same kind of thing (i.e. identifiers of personnel), and therefore should be shown in only one column in a normalized table.  To prove that this is not
    normalized, assume that "Chuck" changes his name to "Charles"; you have to change his name in both columns and several places. The defining characteristic of a normalized table is that you have one fact, one place, one time.
    The final problem is that the adjacency list model does not model subordination. Authority flows downhill in a hierarchy, but If I fire Chuck, I disconnect all of his subordinates from Albert. There are situations (i.e. water pipes) where this is true, but
    that is not the expected situation in this case.
    To show a tree as nested sets, replace the nodes with ovals, and then nest subordinate ovals inside each other. The root will be the largest oval and will contain every other node.  The leaf nodes will be the innermost ovals with nothing else inside them
    and the nesting will show the hierarchical relationship. The (lft, rgt) columns (I cannot use the reserved words LEFT and RIGHT in SQL) are what show the nesting. This is like XML, HTML or parentheses. 
    At this point, the boss_emp_name column is both redundant and denormalized, so it can be dropped. Also, note that the tree structure can be kept in one table and all the information about a node can be put in a second table and they can be joined on employee
    number for queries.
    To convert the graph into a nested sets model think of a little worm crawling along the tree. The worm starts at the top, the root, makes a complete trip around the tree. When he comes to a node, he puts a number in the cell on the side that he is visiting
    and increments his counter.  Each node will get two numbers, one of the right side and one for the left. Computer Science majors will recognize this as a modified preorder tree traversal algorithm. Finally, drop the unneeded OrgChart.boss_emp_name column
    which used to represent the edges of a graph.
    This has some predictable results that we can use for building queries.  The root is always (left = 1, right = 2 * (SELECT COUNT(*) FROM TreeTable)); leaf nodes always have (left + 1 = right); subtrees are defined by the BETWEEN predicate; etc. Here are
    two common queries which can be used to build others:
    1. An employee and all their Supervisors, no matter how deep the tree.
     SELECT O2.*
       FROM OrgChart AS O1, OrgChart AS O2
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND O1.emp_name = :in_emp_name;
    2. The employee and all their subordinates. There is a nice symmetry here.
     SELECT O1.*
       FROM OrgChart AS O1, OrgChart AS O2
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND O2.emp_name = :in_emp_name;
    3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries which each employee controls:
     SELECT O2.emp_name, SUM(S1.salary_amt)
       FROM OrgChart AS O1, OrgChart AS O2,
            Salaries AS S1
      WHERE O1.lft BETWEEN O2.lft AND O2.rgt
        AND S1.emp_name = O2.emp_name 
       GROUP BY O2.emp_name;
    4. To find the level and the size of the subtree rooted at each emp_name, so you can print the tree as an indented listing. 
    SELECT O1.emp_name, 
       SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt 
       THEN O2.sale_amt ELSE 0.00 END) AS sale_amt_tot,
       SUM(CASE WHEN O2.lft BETWEEN O1.lft AND O1.rgt 
       THEN 1 ELSE 0 END) AS subtree_size,
       SUM(CASE WHEN O1.lft BETWEEN O2.lft AND O2.rgt
       THEN 1 ELSE 0 END) AS lvl
      FROM OrgChart AS O1, OrgChart AS O2
     GROUP BY O1.emp_name;
    5. The nested set model has an implied ordering of siblings which the adjacency list model does not. To insert a new node, G1, under part G.  We can insert one node at a time like this:
    BEGIN ATOMIC
    DECLARE rightmost_spread INTEGER;
    SET rightmost_spread 
        = (SELECT rgt 
             FROM Frammis 
            WHERE part = 'G');
    UPDATE Frammis
       SET lft = CASE WHEN lft > rightmost_spread
                      THEN lft + 2
                      ELSE lft END,
           rgt = CASE WHEN rgt >= rightmost_spread
                      THEN rgt + 2
                      ELSE rgt END
     WHERE rgt >= rightmost_spread;
     INSERT INTO Frammis (part, lft, rgt)
     VALUES ('G1', rightmost_spread, (rightmost_spread + 1));
     COMMIT WORK;
    END;
    The idea is to spread the (lft, rgt) numbers after the youngest child of the parent, G in this case, over by two to make room for the new addition, G1.  This procedure will add the new node to the rightmost child position, which helps to preserve the idea
    of an age order among the siblings.
    6. To convert a nested sets model into an adjacency list model:
    SELECT B.emp_name AS boss_emp_name, E.emp_name
      FROM OrgChart AS E
           LEFT OUTER JOIN
           OrgChart AS B
           ON B.lft
              = (SELECT MAX(lft)
                   FROM OrgChart AS S
                  WHERE E.lft > S.lft
                    AND E.lft < S.rgt);
    7. To find the immediate parent of a node: 
    SELECT MAX(P2.lft), MIN(P2.rgt)
      FROM Personnel AS P1, Personnel AS P2
     WHERE P1.lft BETWEEN P2.lft AND P2.rgt 
       AND P1.emp_name = @my_emp_name;
    I have a book on TREES & HIERARCHIES IN SQL which you can get at Amazon.com right now. It has a lot of other programming idioms for nested sets, like levels, structural comparisons, re-arrangement procedures, etc. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Inner Join - whats wrong?

    Hello there,
    I was trying to make an Inner Join, but unfortunately without success.
    there is the code, can someone pls tell me what is wrong??
    DATA: gs_mara TYPE mara,
          gt_mara TYPE STANDARD TABLE OF mara.
    DATA: gs_marc TYPE marc,
          gt_marc TYPE STANDARD TABLE OF marc.
    DATA: gs_makt TYPE makt,
          gt_makt TYPE STANDARD TABLE OF makt.
    DATA: gs_t001w TYPE t001w,
          gt_t001w TYPE STANDARD TABLE OF t001w.
    TYPES: BEGIN OF ts_ausgabe,
           matnr TYPE matnr,
           mtart TYPE mtart,
           matkl TYPE matkl,
           meins TYPE meins,
           werks TYPE werks_d,
           dispo TYPE dispo,
           adrnr TYPE adrnr,
           END OF ts_ausgabe.
    DATA: gs_ausgabe TYPE ts_ausgabe.
    DATA: gt_ausgabe TYPE STANDARD TABLE OF ts_ausgabe.
    SELECT-OPTIONS: pr_matnr FOR gs_mara-matnr,
                    pr_werks FOR gs_marc-werks.
    START-OF-SELECTION.
      select a~matnr b~werks c~dispo d~adrnr e~mtart f~matkl g~meins
      INTO CORRESPONDING FIELDS OF TABLE gt_ausgabe
      FROM        mara AS a  INNER  JOIN marc AS b
      ON b~matnr = a~matnr
      INNER  JOIN marc AS c  ON c~matnr = a~matnr
      INNER JOIN t001w AS d  ON d~werks = a~matnr 
      INNER  JOIN mara AS e  ON e~matnr = a~matnr
      INNER  JOIN mara AS f  ON f~matnr = a~matnr
      INNER  JOIN mara AS g  ON g~matnr = a~matnr
      where a~matnr = pr_matnr
        and b~werks = pr_werks
        and c~dispo = pr_dispo
        and d~adrnr = pr_adrnr
        and e~mtart = pr_mtart
        and f~matkl = pr_matkl
        and g~meins = pr_meins.
      write: / matnr dispo adrnr mtart matkl meins.
        LOOP AT gt_mara INTO gs_mara.
          READ TABLE gt_marc INTO gs_marc WITH KEY matnr = gs_mara-matnr.
          IF sy-subrc = 0.
            MOVE: gs_mara-matnr TO gs_ausgabe-matnr,
                  gs_mara-mtart TO gs_ausgabe-mtart,
                  gs_mara-matkl TO gs_ausgabe-matkl,
                  gs_mara-meins TO gs_ausgabe-meins,
                  gs_marc-werks TO gs_ausgabe-werks,
                  gs_marc-dispo TO gs_ausgabe-dispo,
                  gs_t001w-adrnr TO gs_ausgabe-adrnr.
            WRITE: / gs_mara-matnr, gs_mara-mtart, gs_mara-matkl, gs_mara-meins, gs_marc-werks, gs_marc-dispo, gs_t001w-adrnr.
            APPEND gs_ausgabe TO gt_ausgabe.
          ENDIF.
        ENDLOOP.
        LOOP AT gt_ausgabe INTO gs_ausgabe.
          WRITE: / sy-vline, gs_ausgabe-matnr,
                   sy-vline, gs_ausgabe-mtart,
                   sy-vline, gs_ausgabe-matkl,
                   sy-vline, gs_ausgabe-meins,
                   sy-vline, gs_ausgabe-werks,
                   sy-vline, gs_ausgabe-dispo,
                   sy-vline, gs_ausgabe-adrnr.
          ULINE.
        ENDLOOP.
    Edited by: Thomas Zloch on Jun 20, 2011 10:19 AM - code tags added

    hi ,
    use this query 
    select a~matnr b~werks b~dispo adrnr mtart matkl meins
      INTO CORRESPONDING FIELDS OF TABLE gt_ausgabe
      FROM        mara AS a  INNER  JOIN marc AS b
      ON b~matnr = a~matnr
    *  INNER  JOIN marc AS c  ON c~matnr = a~matnr
      INNER JOIN t001w AS d  ON d~werks = b~werks 
      where a~matnr = pr_matnr
        and b~werks = pr_werks
        and c~dispo = pr_dispo
        and adrnr = pr_adrnr
        and mtart = pr_mtart
        and matkl = pr_matkl
        and meins = pr_meins.
    Why  you are using mara table and marc table multiple times   ?
    regards
    Deepak.
    Edited by: Deepak Dhamat on Jun 20, 2011 10:31 AM

  • Need help with inner join and distinct rows

    Hey Guys,
    i have
    1) BaseEnv Table 
    2) Link Table
    3) BaseData Table
    Link table has three columns Id,BaseEnvId,BaseDataId 
    the BaseEnvID is unique in the table where as BaseDataId can be repeated i.e multile rows of BaseEnv Table can point to same BaseData  table row
    Now i want to do  BaseEnvTable inner join Link Table inner join BaseData Table and select 5 columsn ; Name,SyncName,Version,PPO,DOM  from the BaseData table.. the problem is that after i do the inner join I get duplciate records..
    i want to eliminate the duplicate records , can any one help me here

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. Now we have to guess and type, guess and type, etc. because of your bad manners. 
    CREATE TABLE Base_Env
    (base_env_id CHAR(10) NOT NULL PRIMARY KEY,
    Think about the name Base_Data; do you have lots of tables without data? Silly, unh? 
    CREATE TABLE Base_Data
    (base_data_id CHAR(10) NOT NULL PRIMARY KEY,
    Your Links table is wrong in concept and implementation. The term “link” refers to a pointer chain structure used in network databases and makes no sense in RDBMS. There is no generic, magic, universal “id” in RDBMS! People that do this are called “id-iots”
    in SQL slang. 
    We can model a particular relationship in a table by referencing the keys in other tables. But we need to know if the relationship is 1:1, 1:m, or n:m. This is the membership of the relationship. Your narrative implies this: 
    CREATE TABLE Links
    (base_env_id CHAR(10) NOT NULL UNIQUE
       REFERENCES Base_Env (base_env_id),
     base_data_id CHAR(10) NOT NULL
       REFERENCES Base_Data (base_data_id));
    >> The base_env_id is unique in the table where as base_data_id can be repeated I.e multiple rows of Base_Env Table can point [sic] to same Base_Data table row. <<
    Again, RDBMS has no pointers! We have referenced an referencing tables. This is a fundamental concept. 
    That narrative you posted has no ON clauses! And the narrative is also wrong. There is no generic “name”, etc. What tables were used in your non-query? Replace the ?? in this skeleton: 
    SELECT ??.something_name, ??.sync_name, ??.something_version, 
           ??.ppo, ??.dom
    FROM Base_Env AS E, Links AS L, Base_Data AS D
    WHERE ?????????;
    >> I want to eliminate the duplicate records [sic], can any one help me here?<<
    Where is the sample data? Where is the results? Please read a book on RDBMS so you can post correct SQL and try again. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Inner join query

    Hi all,
    I want to query a inner join via some tools in sap GUI. till now, i could not query a inner join between two tables via SE11. can someone tell are there some other ways to achieve this?
    any response will be awarded!
    thanks and regards,
    samson

    hi samson,
    Proper use of Inner Join
    When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from them. This certainly reduces the load on the network.
    Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.
    Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
                 Select aairln alnnam bfligh bcntry into table int_airdet
    example 2:--
    Inner join: If you have common fields between 2 or more tables, its betterto use Inner join.
    Check the below example:
    VBAK & VBAP table has common fields, hence we can use inner join.
    SELECT akunnr avbeln anetwr abnddt a~knumv
    avkbur aerdat avdatu aaugru
    aktext bmatnr barktx bkwmeng b~kzwi6
    bvolum bposnr b~kdmat
    INTO CORRESPONDING FIELDS OF TABLE g_t_quot
    FROM vbak AS a INNER JOIN vbap AS b
    ON avbeln = bvbeln
    WHERE a~vbeln IN so_vbeln
    AND a~trvog ='2'
    AND a~vkorg IN so_vkorg
    AND a~vtweg IN so_vtweg
    AND a~vkbur IN so_vkbur
    AND a~audat IN so_audat
    AND a~kunnr IN so_kunag.
    FOR ALL ENTRIES:
    If you get some data into one internal table and if you want to fetch data from other table based on it, use FOR ALL ENTRIES.
    g_t_quot is an internal table.
    SELECT spras augru bezei FROM tvaut INTO TABLE g_t_tvaut
    FOR ALL ENTRIES IN g_t_quot
    WHERE augru = g_t_quot-augru AND spras = sy-langu.
                From zairln as a inner join zflight as b on aairln = bairln.
    In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.

  • Urgent: inner joins

    i wanna add inner joins in my report,plz give me d link of websites which provide suitable example.. if u r having example of it den do tell me...
    its really urgent...

    HI
    SELECT - join
    ... [(] {dbtab_left [AS tabalias_left]} | join
              {[INNER] JOIN}|{LEFT [OUTER] JOIN}
                {dbtab_right [AS tabalias_right] ON join_cond} [)] ...  .
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following additions not be used: NOT, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
                p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
             fldate TYPE sflight-fldate,
             carrname TYPE scarr-carrname,
             connid   TYPE spfli-connid,
           END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
                   WITH UNIQUE KEY fldate carrname connid.
    SELECT ccarrname pconnid f~fldate
           INTO CORRESPONDING FIELDS OF TABLE itab
           FROM ( ( scarr AS c
             INNER JOIN spfli AS p ON pcarrid   = ccarrid
                                  AND p~cityfrom = p_cityfr
                                  AND p~cityto   = p_cityto )
             INNER JOIN sflight AS f ON fcarrid = pcarrid
                                    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
      WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
            carrid   TYPE scarr-carrid,
            carrname TYPE scarr-carrname,
            connid   TYPE spfli-connid,
          END OF wa,
          itab LIKE SORTED TABLE OF wa
                    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
           INTO CORRESPONDING FIELDS OF TABLE itab
           FROM scarr AS s
           LEFT OUTER JOIN spfli AS p ON scarrid   =  pcarrid
                                      AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
      IF wa-connid = '0000'.
        WRITE: / wa-carrid, wa-carrname.
      ENDIF.
    ENDLOOP.
    REWARD if usefull

  • Reports - Inner Joins

    Dear Friends,
    I need to prepare a classic report based on the following parameters :
    I would like to know, how to join these three tables using Inner Joins - MARA, MARC, MSTA.
    I should be able to view the fields from these tables.
    I tried out with the common fields from these tables, viz. MARA - MATNR - MARC, MARC - WERKS - MSTA.
    I would appreciate, if anyone replies me with the select statement using the above mentioned tables using Inner Joins statement with any common fields .
    Thanking you in anticipation.

    Dear dinesh kumar
    1. We can join the three tables with matnr field.
    2. WERKS has to be provided from the program - (plant).
       ie. For which plant, data is required.
    3. Due to MSTA table, you may get multiple records
       for same MATNR. bcos of maintenance records
       by different departments in MSTA Table.
    If it helps, pls give points.
    REPORT abc.
    data : begin of itab occurs 0,
           matnr like mara-matnr,
           "---- Other Fields
           end of itab.
    data : matnr like mara-matnr.
    data : werks like marc-werks.
    Query
    select a~matnr
    into table itab
    from mara  as a
    inner join marc as b
    on amatnr = bmatnr
    inner join msta as c
    on amatnr = cmatnr
    Required Conditions From Program
    where a~matnr = matnr
    and b~werks = werks.
    Thanks & Regards,
    Amit Mittal.

  • Syntax of  inner join

    hello sir,
                 plz tell me the syntax of inner join for three tables.

    Syntax
    ... [(] {dbtab_left [AS tabalias_left]} | join
    {[INNER] JOIN}|{LEFT [OUTER] JOIN}
    {dbtab_right [AS tabalias_right] ON join_cond} [)] ... .
    Effect
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN . Depending on the type of join, a join expression can be either an inner ( INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following language elements may not be used: BETWEEN, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
    p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
    fldate TYPE sflight-fldate,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY fldate carrname connid.
    SELECT ccarrname pconnid f~fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( scarr AS c
    INNER JOIN spfli AS p ON pcarrid = ccarrid
    AND p~cityfrom = p_cityfr
    AND p~cityto = p_cityto )
    INNER JOIN sflight AS f ON fcarrid = pcarrid
    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
    WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
    carrid TYPE scarr-carrid,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
    AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
    IF wa-connid = '0000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDIF.
    ENDLOOP.
    we r using 2 type of joins in abap they are
    1) inner join.
    this will join 2 tables using an common fiend and return the result with field values wich are common in both the tables
    itab1 itab2
    a b c a d
    1 2 3 1 5
    2 3 4 3 6
    after innerjoining itab1 n itab2 on field a we wil get the o/p as
    a b c d
    1 2 3 5
    only common field is taken..
    2)left outer join
    here it wil work in opossite way it will give values whic are not common
    itab1 itab2
    a b c a d
    1 2 3 1 5
    2 3 4 3 6
    after left outer joining itab1 n itab2 on field a we wil get the o/p as
    a b c d
    2 3 4
    only fields which are not common is taken from the left table..other field(d here) wil be empty
    I think it will help u.
    Reward Points if helpful.
    Check for ALVROBOT.COM also it is also helpful.

Maybe you are looking for

  • Ever since upgrading to Mavericks, Adobe Flash Player doesn't work.

    I upgraded from Snow Leopard to Mavericks recently and since then, sites do not recognize that I have Adobe Flash Player installed at all. I currently have the most updated version: "Plug-in version 11.9.900.170 is installed." I noticed this when fam

  • 2 ipods and itunes accounts on one computer

    We have one computer in our home, and it has multiple accounts.  My iTouch is synced with my iTunes account and my nephews iTouch is synced with his iTunes account.  I was in the process of updating his ipod for him so he could use the features on hi

  • DS XI3.2 SP1 - Problem when starting RFC server from management console

    Hi, We're using DataServices XI 3.2 SP1 FP1 on a windows 2008 server 64bits to load SAP BW. We have set up an external system in SAP BW called "DI_SOURCE" and then successfully created a RFC server interface (DI_SOURCE) within the management console.

  • Binding a JavaFX variable to a Java class instance variable

    Hi, I am pretty new to JavaFX but have been developing in Java for many years. I am trying to develop a JavaFX webservice client. What I am doing is creating a basic scene that displays the data values that I am polling with a Java class that extends

  • Purchase Order Tax Jurisdiction Code Default

    Hello, I have a business requirement to have my tax code default based off of Delivery Address Region field. I can achive this by creating a custom condition table with region, creating a custom access sequence, inserting the custom table, and attach