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

Similar Messages

  • What is left join /right join / out join/ inner join/please give example!

    what is left join /right join / out join/ inner join/please give example!
    thanks

    Maybe these examples will give you an idea...
    SQL> select * from t1;
            ID
             1
             2
             3
             4
    SQL> select * from t2;
            ID
             3
             4
             5
             6
    -- LEFT OUTER JOIN
    SQL> select t1.id, t2.id
      2  from t1 LEFT OUTER JOIN t2 ON (t1.id = t2.id);
            ID         ID
             3          3
             4          4
             1
             2
    -- RIGHT OUTER JOIN
    SQL> select t1.id, t2.id
      2  from t1 RIGHT OUTER JOIN t2 ON (t1.id = t2.id);
            ID         ID
             3          3
             4          4
                        6
                        5
    -- LEFT JOIN (SAME AS LEFT OUTER JOIN)
    SQL> ed
    Wrote file afiedt.buf
      1  select t1.id, t2.id
      2* from t1 LEFT JOIN t2 ON (t1.id = t2.id)
    SQL> /
            ID         ID
             3          3
             4          4
             1
             2
    -- RIGHT JOIN (SAME AS RIGHT OUTER JOIN)
    SQL> ed
    Wrote file afiedt.buf
      1  select t1.id, t2.id
      2* from t1 RIGHT JOIN t2 ON (t1.id = t2.id)
    SQL> /
            ID         ID
             3          3
             4          4
                        6
                        5
    -- INNER JOIN (REGULAR JOIN)
    SQL> ed
    Wrote file afiedt.buf
      1  select t1.id, t2.id
      2* from t1 INNER JOIN t2 ON (t1.id = t2.id)
    SQL> /
            ID         ID
             3          3
             4          4
    -- FULL OUTER JOIN
    SQL> ed
    Wrote file afiedt.buf
      1  select t1.id, t2.id
      2* from t1 FULL OUTER JOIN t2 ON (t1.id = t2.id)
    SQL> /
            ID         ID
             3          3
             4          4
             1
             2
                        6
                        5
    6 rows selected.
    SQL>

  • What is syntax for inner join of Select statement with  Secondary Index

    Hi Genies,
                    Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
    SELECT *  INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
                 INNER JOIN COBK  AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
                 WHERE A~OBJNR = OBJNR
                 AND A~GJAHR = CURRY
                 AND B~GJAHR = CURRY
                 AND A~RBEST = ''
                 AND A~BEKNZ = 'S'
                 AND B~BELNR NE WA_COBK-BELNR
                 AND B~AWREF_REV = ''
                 AND B~AWORG_REV = ''
                 AND B~KOKRS = WA_COIOB-KOKRS
                 AND B~BLDAT BETWEEN START_DATE AND END_DATE
                 AND B~BLART IN ('SA','KA','KR','AB')  %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
    index name is ZBU.
    please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
    Regards,
            Thangam.P

    Hi Genies,
                    Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
    SELECT *  INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
                 INNER JOIN COBK  AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
                 WHERE A~OBJNR = OBJNR
                 AND A~GJAHR = CURRY
                 AND B~GJAHR = CURRY
                 AND A~RBEST = ''
                 AND A~BEKNZ = 'S'
                 AND B~BELNR NE WA_COBK-BELNR
                 AND B~AWREF_REV = ''
                 AND B~AWORG_REV = ''
                 AND B~KOKRS = WA_COIOB-KOKRS
                 AND B~BLDAT BETWEEN START_DATE AND END_DATE
                 AND B~BLART IN ('SA','KA','KR','AB')  %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
    index name is ZBU.
    please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
    Regards,
            Thangam.P

  • Regarding : What is used in place of inner join

    hi,
    i want to know that we use to have inner joins in our reports and i want to know is there anything which can be used in place of it?

    Hi,
    In place of inner join you can use  FOR ALL ENTRIES.
    reward point if useful.
    Regards
    Kumar M

  • For All Entries is NOT better than INNER JOIN in most cases

    I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
    For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
    There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
    It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
    FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
    too many records are transferred.
    People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
    Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
    There are several kinds of views:
    - projection views, i.e. only one table involved just fields reduced
    - join views, several tables, joins conditions stored in dictionary
    - materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
    Only the last one creates real overhead. It should be the exception.
    Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
    Abraham Bukit  points out:
    If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
    If they all are transaction table which are not buffered and are not cluster tables.  
    He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
    Thomas Zloch says, regarding buffered tables:
    At least think twice, maybe compare runtimes if in doubt. 
    So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
    Kind regards
    Matt

    To give food for thought here's an example I  gave in a thread:
    If you have a statement like
    SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
    SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
    rsdb/prefer_union_all = 0 =>
    SELECT ... WHERE f = FAE_itab[1]-f
              OR    f = FAE_itab[2]-f
              OR    f = FAE_itab[N]-f
    You have some influence  of the generated statement type: Instead of OR'ed fields an IN list can be used
    if you have only a single coulmn N to compare:
    rsdb/prefer_in_itab_opt parameter:
    SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
    rsdb/prefer_union_all = 1 =>
    SELECT ... WHERE f = FAE_itab[1]-f
    UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
    UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
    see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
    As you can see for the 2nd parameter several statements are generated and combined with a UNION ALL,
    the first setting generates statements with OR's (or uses IN  if possible) for the entries in FAE_itab.
    I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in ST05)
    Select myid into table t_tabcount from mydbtable
      for all entries in t_table    " 484 entries
        where myid = t_table-myid .
    ST05 trace:
    |Transaction SEU_INT|Work process no 0|Proc.type  DIA|Client  200|User |
    |Duration |Obj. name |Op.    |Recs.|RC    |Statement|
    | 640|mydbtable |PREPARE|   |  0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5|
    | 2|mydbtable |OPEN   |   |  0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72 |
    | 2.536|mydbtable |FETCH  |    0|  1403|   |
    | 3|mydbtable |REOPEN |   |  0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72 |
    | 118|mydbtable |FETCH  |  0|  |
    | 2|mydbtable |REOPEN |  |  0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72     |
    | 3|mydbtable |REOPEN |  |  0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72  |
    | 94|mydbtable |FETCH  | 0| 1403|   |
    | 2|mydbtable |REOPEN |   |  0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72 |
    You see the IN list contained 5 entries each , wich made up about 97 statements for all 484 entries.
    For every statment you have a single fetch operation wich means a separate access to the database.
    If you would replace the FAE with a join you would only have one fetch to the database.
    With the example above we can derive these observations:
    1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
    at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
    2. A second impact is that with every statement execution you trigger the allocation of database resources
    wich will contribute to the overhead described above.
    Said that, FAE  can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
    Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed

  • 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?

  • Why can't i use "INNER JOIN" in a query for SQL Server with JDBC??????

    Hi,
    I'm trying to execute some SQL queries and I just don't understand what's wrong.
    I�m using Tomcat and SQL Server in order to do this, but when I�m try to execute a query with a INNER JOIN statements Tomcat raise a SQL exception... at the very first time I thought there was a problem with database connection but I realize that a simple query to a table works pretty well. then I found out some problems with JDBC:ODBC.... so I install JDBC for SQL Server 2000 and test with the same simple query and works..... so, I come to a conclusion.... INNER JOIN or JOIN statements can't be used in JDBC..... please... somebody tell I�m wrong and give me a hand...
    I'm using TOMCAT 4 and JDK 1.4 SQL Server 2000
    Error occurs when executeQuery() is called.... not prepareStatement().... ??????
    Driver DriverRecResult = (Driver)Class.forName(driver).newInstance();
    Connection ConnRecResult = DriverManager.getConnection(DSN,user,password);
    PreparedStatement StatementRecResult = ConnRecResult.prepareStatement(query);
    ResultSet RecResult = StatementRecResult.executeQuery(); <---- Exception raise here
    So much tahnks in advance,

    That's exactly what I think, driver it's raising the exception, but I don't know why.... i test the same query with INNER JOIN directly from SQL Query Analyser and it's works perfectly, my problem ain't SQL, but JSP and JDBC 'cause i'm a newbie about these issues.
    Common sense tell me possible problems lie in SQLServer drivers 'cause i run the same pages on JRUN through jdbc:odbc and do works well, but by now i just depend on Tomcat.....
    I've installed SQL Server drivers for JDBC but i just find it doesn't work fully... could be the version of JDK i've installed? what version do i need?
    ( I'm running Tomcat 4 with JDK 1.4 & SQL Server 2000 W2K )
    thanks for reply.

  • 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

  • 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

  • Short Dump on Inner Join

    Hello Experts,
    I'm trying to write a Inner join on VBAK and VBAP because i need to get data from both tables.  When I try to execute the following code I'm getting a short dump "Error in module RSQL of the database Interface". Can anybody see what's wrong with this select.
           begin of t_sales_order,
             vbeln  type vbak-vbeln,    "Sales Order
             auart  type vbak-auart,     "Order Type
             audat  type vbak-audat,     "Shipment Creation date field
             posnr  type vbap-posnr,    "Items
             kdmat  type vbap-matnr,    "Lead Pin
             cuobj  type vbap-cuobj,    "Configuration Object ID
             end of t_sales_order,
    data: lwa_sales_order           type t_Sales_Order.
          select single avbeln aaudat a~auart
                        bposnr bkdmat b~cuobj
                          into lwa_sales_order
                             from vbak as a inner join vbap as b
                                  on avbeln = bvbeln
                                     where b~kdmat = pv_pin_number.
    Many thanks in advance.

    Hi
    Your internal table fields sequences are not followed in Inner Join.
    begin of t_sales_order,
    vbeln type vbak-vbeln, "Sales Order
    auart type vbak-auart, "Order Type
    audat type vbak-audat, "Shipment Creation date field
    posnr type vbap-posnr, "Items
    kdmat type vbap-matnr, "Lead Pin
    cuobj type vbap-cuobj, "Configuration Object ID
    end of t_sales_order,
    select single a~vbeln *a~auart* a~audat
    b~posnr b~kdmat b~cuobj
    into lwa_sales_order
    from vbak as a inner join vbap as b
    on a~vbeln = b~vbeln
    where b~kdmat = pv_pin_number.
    Please check the above code
    Shiva

  • Time Out by select on DD04L inner join DD04T

    Hello,
    I just installed ERP 2005. After the import of a language package (SMLT, IT, FR, ES) I get some problem.
    If I logon with EN or IT (and I think with any language other than DE) many transaction get a Time Out error in the function module DDIF_FIELDINFO_GET by the following selection:
    *             get texts of primary language (inner join here !)
                  SELECT DD04L~ROLLNAME DD04L~DOMNAME DD04L~HEADLEN
                         DD04L~SCRLEN1  DD04L~SCRLEN2 DD04L~SCRLEN3
                         DD04T~DDLANGUAGE DD04T~DDTEXT    DD04T~REPTEXT
                         DD04T~SCRTEXT_S  DD04T~SCRTEXT_M DD04T~SCRTEXT_L
                         INTO TABLE Rolltexts
                         FROM DD04L inner JOIN DD04T
                         ON DD04T~ROLLNAME = DD04L~ROLLNAME AND
                            DD04T~AS4LOCAL = 'A' AND
                            DD04T~DDLANGUAGE = langu_loc
                         FOR ALL ENTRIES IN missing
                         WHERE DD04L~ROLLNAME = missing-ROLLNAME
                           AND DD04L~AS4LOCAL = 'A'.
    That is, the ERP is using sequential read instead of direct read.
    Any idea is welcomed.
    Thanks & regards,
    Tommaso

    Hello,
    Thanks for your replies.
    I checked OSS and I found nothing.
    ST05 gives me this SQL command: (more than 500 sec!)
    SELECT T_00 . "ROLLNAME" , T_00 . "DOMNAME" , T_00 . "HEADLEN" , T_00 . "SCRLEN1" , T_00 . "SCRLEN2" , T_00 . "SCRLEN3" , T_01 . "DDLANGUAGE" , T_01 . "DDTEXT" , T_01 . "REPTEXT" , T_01 . "SCRTEXT_S" , T_01 . "SCRTEXT_M" , T_01 . "SCRTEXT_L" FROM "DD04L"
    T_00 INNER JOIN "DD04T" T_01 ON T_01 . "ROLLNAME" = T_00 . "ROLLNAME" AND T_01 . "AS4LOCAL" = 'A' AND T_01 . "DDLANGUAGE" = 'I' WHERE T_00 . "ROLLNAME" = 'VAL_TEXT' AND T_00 . "AS4LOCAL" = 'A'
    I executed it in SQL Studio and I got also a big execution time.
    But if I try
    SELECT  "ROLLNAME" ,  "DOMNAME" ,  "HEADLEN" , "SCRLEN1" , "SCRLEN2" , "SCRLEN3"  FROM "DD04L" WHERE T_00 . "ROLLNAME" = 'VAL_TEXT' AND T_00 . "AS4LOCAL" = 'A'
    I get the result in 1 ms.
    Is there something wrong in the inner join?
    What does it mean the operation "REOPEN"?
    How can I see from ST05 if an index has been used?
    Thanks & Regards,
    Tommaso

  • Select querry using inner join

    Hi Friends,
    I need to fetch data from two tables, I used inner join but I am not able to fetch the data in some fields can any one tell me what is wrong in this select querry.
    SELECT but000~partner
             but000~name_org1
             but000~name_first
             but000~name_last
             but000~bpext
          FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart
        INTO table lt_but000
        WHERE but000~partner IN so_part
        AND dfkkop~faedn IN so_faedn.
    Thanx in advance,
    Parvez

    hi Lutin,
    SELECT but000~partner
    but000~name_org1
    but000~name_first
    but000~name_last
    but000~bpext
    FROM but000 INNER JOIN dfkkop ON but000partner = dfkkopgpart  <------check this condition,it has to *satisfy  both table                                                                        
    INTO table lt_but000
    WHERE but000~partner IN so_part
    AND dfkkop~faedn IN so_faedn.
    Regards,
    siva
    Message was edited by:
            SivaKumar

  • Inner join.   error.  too long. unique. unique

    hi,
    I am a beginer to ABAP and trying to  do an inner join using 3 tables that are given by SAP
    scustom, spfli, and sbook. I want to join these 3 tables and  get
    the customer booking info and wants the result of
    customer_no , cust_name, Booking_ID, City_From, City_To, etc.
    my query i s below.
    select cid cname bbookid bconnid bfldate fcityfrom f~cityto
    into table it_scust
    from ((scustom as c inner join sbook as b
    on cid = bcustomid)
    inner join spfli as f on fconnid = bconnid and fcarrid = bcarrid).
    when i execute the program i am getting the error  that the 'query is too long. unique. unique. unique.'.
    If  I am joing only two tables it is working fine. Is there something wrong with my query?  Any ideas on this? Please help.
    Thanks in advance.

    Hi neeraja,
    what ever the code you have written is fine but it is unique/ too long means  the code you have written is not ending perfectly which is not identified by syntax error. your code is
    select cid cname bbookid bconnid bfldate fcityfrom f~cityto
    into table it_scust
    from ((scustom as c inner join sbook as b
    on cid = bcustomid)
    inner join spfli as f on fconnid = bconnid and fcarrid = bcarrid).
    iam sending the same code but with little modification just try this u will get the output.
    select cid cname bbookid bconnid bfldate fcityfrom f~cityto
    into table it_scust
    from (scustom as c inner join sbook as b
    on cid = bcustomid)
    inner join spfli as f on fconnid = bconnid and fcarrid = bcarrid.
    find the difference what i made.
    pls reward points if it is helpful.

  • INNER JOIN Display Issues

    Hello,
    I am haing troubles displaying the author_name using the
    author_id in a testcase table and author table were author_id is
    the primary key in the author table and the foreign key in the
    author table. Here is my INNER JOIN SQL:
    $query_rsListAuthor = "SELECT author_name FROM author INNER
    JOIN testcase WHERE author.author_id = testcase.author_id";
    $rsListAuthor = mysql_query($query_rsListAuthor, $QA) or
    die(mysql_error());
    $row_rsListAuthor = mysql_fetch_assoc($rsListAuthor);
    $totalRows_rsListAuthor = mysql_num_rows($rsListAuthor);
    I can't seem to display the author_name when I use this:
    <?php echo $row_rsListAuthor['author_name'];
    ?></p>
    Any thoughts as to what I am doing wrong?
    Thanks,
    Ron

    How many matching records do you actually have between the 2
    tables?
    Are you seeing only 1 match on the web page or when you hit
    test in the recordset dialog window? If it is the web page you may
    need to slap a repeat region on it. Also make sure you have the
    correct recordset selected in the repeat region from the drop down
    menu. If you have multiple recordsets on the page because it always
    defaults to the first one in the menu

  • Inner join need help

    hi
    I have following data
    create table test1 (ind int,idd varchar(20), sec int, amt float)
    create table test2 (ind int, id1 varchar(10), id2 varchar(10), sec int, qty float)
    insert into test1 values (11, '1aa',1,100);
    insert into test1 values (12, '1aa',1,200);
    insert into test1 values (13, '2bb',2,500);
    insert into test1 values ( 14,'2bb',2,600);
    insert into test1 values ( 15, '3cc',3,100);
    insert into test1 values ( 16, '4dd',4,100);
    insert into test1 values ( 17, '1aa',5,5100);
    insert into test1 values ( 18, '1aa',6,100);
    insert into test2 values( 1, '1','aa',1, 300);
    insert into test2 values( 2, '1','aa',1, 300);
    insert into test2 values( 3, '2','bb',2, 700);
    insert into test2 values( 4, '2','bb',2, 100);
    insert into test2 values( 5, '3','cc',3, 400);
    insert into test2 values( 6, '1','aa',5, 3100);
    insert into test2 values( 7, '1','aa',6, 7100);
    select test2.ind, idd, id1||id2 , test1.sec, amt, qty from test1 inner join test2 on idd=id1||id2 and test1.sec=test2.sec
    order by indI am getting 11 records
    1     1aa     1aa     1     100     300
         1     1aa     1aa     1     200     300
         2     1aa     1aa     1     100     300
         2     1aa     1aa     1     200     300
         3     2bb     2bb     2     500     700
         3     2bb     2bb     2     600     700
         4     2bb     2bb     2     600     100
         4     2bb     2bb     2     500     100
         5     3cc     3cc     3     100     400
         6     1aa     1aa     5     5100     3100
         7     1aa     1aa     6     100     7100
    and following is my desired output
         1     1aa     1aa     1     100     300
         2     1aa     1aa     1     200     300
         3     2bb     2bb     2     500     700
         4     2bb     2bb     2     600     100
         5     3cc     3cc     3     100     400
         6     1aa     1aa     5     5100     3100
         7     1aa     1aa     6     100     7100
    please help

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statements! That's very helpful.
    It's also helpful if you explain how you get the results you want from that data.
    Why do you want 7 rows of output, not 11?
    Given that you do want 7 rows of output, why do you want the results you posted, and not
    IND  IDD  ID1_ID2  SEC  AMT  QTY
    1    1aa  1aa        1     200  300
    2    1aa  1aa        1     200  300
    ...or
    IND  IDD  ID1_ID2  SEC  AMT  QTY
    1    1aa  1aa         1     100  300
    2    1aa  1aa        1     100  300
    ...or some other combination? Don't force people to spend time guessing, and don't give them a chance to guess wrong.
    It looks like you're getting the output you want now, except when there are multiple rows with the same idd and sec in test1 (or the same id1, id2 and sec in test2). These are the join columns.
    It looks like you only want one row of output for each gropup that has the same join columns.
    Within each of those groups, do you only want
    the row with the lowest test1.ind joined to the row with the lowest test2.ind,
    the row with the 2nd lowest test1.ind joined to the row with the 2nd lowest test2.ind,
    the row with the 3rd lowest test1.ind joined to the row with the 3rd lowest test2.ind,
    and so on?
    If so, use the analytic ROW_NUMBER functions to indicate whihc i the lowest, 2nd lowest, 3rd lowest, and so on:
    WITH   test1_with_r_num  AS
         SELECT     ind, idd, sec, amt
         ,     ROW_NUMBER () OVER ( PARTITION BY  idd, sec
                                   ORDER BY          ind
                           )         AS r_num
         FROM    test1
    ,     test2_with_r_num  AS
         SELECT     ind, id1, id2, sec, qty
         ,     ROW_NUMBER () OVER ( PARTITION BY  id1, id2, sec
                                   ORDER BY          ind
                           )         AS r_num
         FROM     test2
    select    t2.ind
    ,        t1.idd
    ,        t2.id1 || t2.id2     AS id1_id2
    ,       t1.sec
    ,        t1.amt
    ,       t2.qty
    from                 test1_with_r_num     t1
    inner join          test2_with_r_num      t2     on     t1.idd       = t2.id1 || t2.id2
                                            and     t1.sec       = t2.sec
                                  and     t1.r_num  = t2.r_num
    order by  t2.ind
    ;This happens to give the results you requested from the data you posted. It may be purely by coincidence.
    What if there are an unequal number of rows with the same join conditions in the two tables?
    For example, what if we add another row to test1:
    insert into test1 (ind, idd, sec, amt) values (91, '1aa',1,125);but don't add any new rows to test2?
    What if we add a row only to test2
    insert into test2 (ind, id1, id2, sec, ity) values( 9, '1','aa',6, 7199);? What results would you want in these cases?

Maybe you are looking for

  • How can I upload a photo to a website?

    how do I post pictures from album on my ipad  to Facebook or other websites?

  • Ovi Suite can't detect my device

    I have to connect my C6 to Ovi Suite but why is it that Ovi can't detect it? I connected my phone by the use of both USB and Bluetooth, and both won't work. Help please :-( Thanks!

  • Calendar function not working in report launch form

    We are currently using Headstart 6.5.3.1 for 9i. When we invoke the calendar function for a date parameter in the report launch form (qms0012f), we get the error-message ORA-6508: could not find program unit being called in PL/SQL Program Unit qms$ca

  • Call report from forms6i, use report server from 10gAS

    Hi there, I have been searching for any info I can get that will help me to do the following: I want to call an Oracle 6i report from Forms6i but I want to specify a Report Server running on an Oracle10gAS box. Can this be done in a client/server fas

  • Differences in FA and AA

    Hi all, I have a problem with AA. We have depreciated an asset last year (2009) MANUALLY after its END of LIFE and made it ZERO. After that we came to know that a posting of 10K has not been carried out in FI for yr 2000. But the same has been posted