Code to Join three tables.

Hi All,
I am a fresher to this ABAP.
I have an task to join three tables which doesn't take much effort. But the problem is: the tables have same columns, (name, age and city) in all the three tables.
The layout is as shown below:
Table 1  ( T1 )            Table 2  ( T2 )          Table 3 ( T3 )
  name | age | city      name | age | city        name | age | city    -
Anju   21     HDD      Anju   20     BGH       Anju    21    SFF
Julie   23     JUH       Julie   24     JUH        Julie   20     JUH
Now, there should be a selection screen. If I enter a value for this varaible as "Anju", The output should be like:
Col       T1        T2      T3
Name    Anju     Anju    Anju
Age       21        20       21
City       HDD    BGH    SFF
I am unable to appraoch how to solve this issue. Any pointers would be of great help.
Thanks in advance,
Anjum.
Edited by: nasarat anjum on Apr 23, 2008 8:43 AM

Hi,
U can take three internal tables for each of ur tables T1,T2,T3. Fetch the respective table data into ur internal tables.
Then write,
loop at itab1.
read table itba2 with key name eq itab1-name.
read table itab3 with key name eq itab1-name.
write : / name under <name heading>,
            itab1-name under <T1 heading>,
            itab2-name under <T2 heading>,
            itab3-name under <T3 heading>.
write : / age under <age heading>,
            itab1-age under <T1 heading>,
            itab2-age under <T2 heading>,
            itab3-age under <T3 heading>.
write : / city under <city heading>,
            itab1-city under <T1 heading>,
            itab2-city under <T2 heading>,
            itab3-city under <T3 heading>.
<removed by moderator>
Thanks
Edited by: Mike Pokraka on Aug 6, 2008 8:30 AM

Similar Messages

  • Joining three tables

    I have to join three tables but i m getting error as given below:
    Error i m getting-
    Syntax error(missing operator) in query expression 'invoice.INVOICE_NO=inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO=inv_ent_main.INVOICE_N'.
    My Query is-
    "select inv_ent_main.EXPORTER,inv_ent_main.INVOICE_NO,inv_ent_main.INVOICE_DATE,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_AMOUNT,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_PIECES,inv_ent_main.TOTAL_AREA,invoice.ORDER_NO,invoice.OTHER_REF,invoice.CONSIGN1,invoice.CONSIGN2,invoice.CONSIGN3,invoice.CONSIGN4,invoice.CONSIGN5,invoice.DLV_TERMS,invoice.PAYMENT_TERMS,invoice.PRE_CARRIAGE,invoice.PR_CARRIER,invoice.DESTINATION,invoice.COUNTRY_DESTINATION,invoice.VESS_FLIGHT,invoice.PORT_LOAD,invoice.PORT_DSCH,invoice.MARK1,invoice.MARK2,invoice.CURRENCY,invoice.GOODS_DESCRIPTION,invoice.CFB,invoice.GROSS_WEIGHT,invoice.NET_WEIGHT,invoice.WOOL,invoice.COTTON
    from inv_ent_main INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO";
    MCA,LUCKNOW.

    The last character in the error message has missing "O" when compare to the actual query you have posted. Please rerun it an verify or you can try the below query. You need to post DDL for all the 3 tables so that we can test.
    select
    inv_ent_main.EXPORTER,
    inv_ent_main.INVOICE_NO,
    inv_ent_main.INVOICE_DATE,
    inv_ent_main.BALE_COUNT,
    inv_ent_main.TOTAL_AMOUNT,
    inv_ent_main.BALE_COUNT,
    inv_ent_main.TOTAL_PIECES,
    inv_ent_main.TOTAL_AREA,
    invoice.ORDER_NO,
    invoice.OTHER_REF,
    invoice.CONSIGN1,
    invoice.CONSIGN2,
    invoice.CONSIGN3,
    invoice.CONSIGN4,
    invoice.CONSIGN5,
    invoice.DLV_TERMS,
    invoice.PAYMENT_TERMS,
    invoice.PRE_CARRIAGE,
    invoice.PR_CARRIER,
    invoice.DESTINATION,
    invoice.COUNTRY_DESTINATION,
    invoice.VESS_FLIGHT,
    invoice.PORT_LOAD,
    invoice.PORT_DSCH,
    invoice.MARK1,
    invoice.MARK2,
    invoice.CURRENCY,
    invoice.GOODS_DESCRIPTION,
    invoice.CFB,
    invoice.GROSS_WEIGHT,
    invoice.NET_WEIGHT,
    invoice.WOOL,
    invoice.COTTON from inv_ent_main
    INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO
    INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO
    Regards, RSingh

  • How to join three tables?

    I have used this query to join three tables but it displays an error : field vbak-vbeln is unknown.
    please help me out..
    SELECT vbak-vbeln vbak-bstnk vbap-matnr vbap-zmeng makt-maktx
    INTO CORRESPONDING FIELDs OF TABLE itab FROM vbak
    inner JOIN vbap ON vbak-vbeln eq vbap-vbeln
    inner JOIN makt ON vbap-matnr eq makt-matnr
    WHERE vbak-bstnk = s_bstnk.

    Hi mohan kumar ,
    just follow the Syntax
    SELECT FLD1 FLD2 FLD3 FLD4 FLD5 INTO CORRESPONDING FIELDS OF TABLE ITAB FROM TABLE1 INNER JOIN TABLE2 ON
    TABLE1FLD1 = TABLE2FLD1 INNER JOIN TABLE3 ON TABLE2FLD2 = TABLE3FLD2 INNER JOIN TABL4 ON  TABLE3FLD3 = TABLE4FLD3
    WHERE FLD1 = 'AA'
    Hope this may be helpful.
    Please reward points if found ok.
    Thanks and regards,
    Rajeshwar.

  • SQL Join Three Tables DW MX2004 ASP

    I'm trying to display records using three tables joined as
    shown in the SQL code below. I'm getting "no data" message when I
    test the result page from the search form. I'm using the advanced
    Dreamweaver form to enter the SQL commands. I have never used this
    feature of Dreamweaver before and I'm not sure if the code below
    follows the way DW MX will understand what I'm trying to do. Below
    is the code based on Standard SQL....not sure if DW compatible...
    This is what I typed in the SQL box:
    SELECT
    ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
    ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resource.resour ceLoginId
    FROM ResourceSkillMapping INNER JOIN Skill ON
    ResourceSkillMapping.skillID = Skill.skillID
    INNER JOIN Resource ON
    ResourceSkillMapping.resourceSkillMapID =
    Resource.resourceSkillMapID
    WHERE (Skill.skillName = '%Skill_asp%') AND
    (Resource.resourceLoginID = '%Agent_asp%')
    AND (Resource.active = 1)
    These is typed in the variables box:
    Variable Default Runtime
    Skill_asp 1 Request.QueryString("skillname")
    Agent_asp 1 Request.QueryString("resourceLoginID")
    I'm using asp and the "Get" url parameters in the search form
    calling the result recordset in DW. I'm connecting to a SQL 2000
    server. Is this notation DW correct? Am I joining the tables
    correctly. The tables are ResourceSkillMapping, Skill and Resource.
    All I need is to be able to search by ResourceLoginID and by
    skillName on all active records (active=1). The plan is to be able
    to click on a result record and go to a detail page to update the
    "CompetencyLevel" field in the resourceSkillMapping table using the
    update behavior in DW.
    Please help as this project is due this Tue and have been
    trying every posibility I could think so far....I have read all the
    DW help facilities many pages on this and still keep getting the
    "no data" message
    Thank you,
    Carlos
    [email protected]

    >> WHERE (Skill.skillName = '%Skill_asp%') AND
    (Resource.resourceLoginID =
    >>'%Agent_asp%')
    I would say that this is where your problem is. Change it to:
    WHERE (Skill.skillName LIKE '%Skill_asp%') AND
    (Resource.resourceLoginID
    LIKE
    '%Agent_asp%')
    and your query should work, unless of course you are actually
    searching for
    2 strings that read %Skill_asp% and %Agent_asp% exactly.
    Pat.
    "ITCoreTeam" <[email protected]> wrote in
    message
    news:[email protected]...
    > I'm trying to display records using three tables joined
    as shown in the
    > SQL
    > code below. I'm getting "no data" message when I test
    the result page from
    > the
    > search form. I'm using the advanced Dreamweaver form to
    enter the SQL
    > commands.
    > I have never used this feature of Dreamweaver before and
    I'm not sure if
    > the
    > code below follows the way DW MX will understand what
    I'm trying to do.
    > Below
    > is the code based on Standard SQL....not sure if DW
    compatible...
    > This is what I typed in the SQL box:
    >
    > SELECT
    >
    ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
    >
    >
    ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resou
    > rce.resourceLoginId
    > FROM ResourceSkillMapping INNER JOIN Skill ON
    ResourceSkillMapping.skillID
    > =
    > Skill.skillID
    > INNER JOIN Resource ON
    ResourceSkillMapping.resourceSkillMapID =
    > Resource.resourceSkillMapID
    > WHERE (Skill.skillName = '%Skill_asp%') AND
    (Resource.resourceLoginID =
    > '%Agent_asp%')
    > AND (Resource.active = 1)
    >
    > These is typed in the variables box:
    > Variable Default Runtime
    > Skill_asp 1 Request.QueryString("skillname")
    > Agent_asp 1 Request.QueryString("resourceLoginID")
    >
    > I'm using asp and the "Get" url parameters in the search
    form calling the
    > result recordset in DW. I'm connecting to a SQL 2000
    server. Is this
    > notation
    > DW correct? Am I joining the tables correctly. The
    tables are
    > ResourceSkillMapping, Skill and Resource. All I need is
    to be able to
    > search by
    > ResourceLoginID and by skillName on all active records
    (active=1). The
    > plan is
    > to be able to click on a result record and go to a
    detail page to update
    > the
    > "CompetencyLevel" field in the resourceSkillMapping
    table using the update
    > behavior in DW.
    > Please help as this project is due this Tue and have
    been trying every
    > posibility I could think so far....I have read all the
    DW help facilities
    > many
    > pages on this and still keep getting the "no data"
    message
    > Thank you,
    > Carlos
    > [email protected]
    >

  • SQL Join Three Tables DW MX2004

    I'm trying to display records using three tables joined as
    shown in the SQL code below. I'm getting "no data" message when I
    test the result page from the search form. I'm using the advanced
    Dreamweaver form to enter the SQL commands. I have never used this
    feature of Dreamweaver before and I'm not sure if the code below
    follows the way DW MX will understand what I'm trying to do. Below
    is the code based on Standard SQL....not sure if DW compatible...
    This is what I typed in the SQL box:
    SELECT
    ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
    ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resource.resour ceLoginId
    FROM ResourceSkillMapping INNER JOIN Skill ON
    ResourceSkillMapping.skillID = Skill.skillID
    INNER JOIN Resource ON
    ResourceSkillMapping.resourceSkillMapID =
    Resource.resourceSkillMapID
    WHERE (Skill.skillName = '%Skill_asp%') AND
    (Resource.resourceLoginID = '%Agent_asp%')
    AND (Resource.active = 1)
    These is typed in the variables box:
    Variable Default Runtime
    Skill_asp 1 Request.QueryString("skillname")
    Agent_asp 1 Request.QueryString("resourceLoginID")
    I'm using asp and the "Get" url parameters in the search form
    calling the result recordset in DW. I'm connecting to a SQL 2000
    server. Is this notation DW correct? Am I joining the tables
    correctly. The tables are ResourceSkillMapping, Skill and Resource.
    All I need is to be able to search by ResourceLoginID and by
    skillName on all active records (active=1). The plan is to be able
    to click on a result record and go to a detail page to update the
    "CompetencyLevel" field in the resourceSkillMapping table using the
    update behavior in DW.
    Please help as this project is due this Tue and have been
    trying every posibility I could think so far....I have read all the
    DW help facilities many pages on this and still keep getting the
    "no data" message
    Thank you,
    Carlos
    [email protected]

    I'm trying to display records using three tables joined as
    shown in the SQL code below. I'm getting "no data" message when I
    test the result page from the search form. I'm using the advanced
    Dreamweaver form to enter the SQL commands. I have never used this
    feature of Dreamweaver before and I'm not sure if the code below
    follows the way DW MX will understand what I'm trying to do. Below
    is the code based on Standard SQL....not sure if DW compatible...
    This is what I typed in the SQL box:
    SELECT
    ResourceSkillMapping.resourceSkillMapID,ResourceSkillMapping.skillID,
    ResourceSkillMapping.competenceLevel,skill.skillname,resource.resourceName,resource.resour ceLoginId
    FROM ResourceSkillMapping INNER JOIN Skill ON
    ResourceSkillMapping.skillID = Skill.skillID
    INNER JOIN Resource ON
    ResourceSkillMapping.resourceSkillMapID =
    Resource.resourceSkillMapID
    WHERE (Skill.skillName = '%Skill_asp%') AND
    (Resource.resourceLoginID = '%Agent_asp%')
    AND (Resource.active = 1)
    These is typed in the variables box:
    Variable Default Runtime
    Skill_asp 1 Request.QueryString("skillname")
    Agent_asp 1 Request.QueryString("resourceLoginID")
    I'm using asp and the "Get" url parameters in the search form
    calling the result recordset in DW. I'm connecting to a SQL 2000
    server. Is this notation DW correct? Am I joining the tables
    correctly. The tables are ResourceSkillMapping, Skill and Resource.
    All I need is to be able to search by ResourceLoginID and by
    skillName on all active records (active=1). The plan is to be able
    to click on a result record and go to a detail page to update the
    "CompetencyLevel" field in the resourceSkillMapping table using the
    update behavior in DW.
    Please help as this project is due this Tue and have been
    trying every posibility I could think so far....I have read all the
    DW help facilities many pages on this and still keep getting the
    "no data" message
    Thank you,
    Carlos
    [email protected]

  • How to join three tables and practical difference between 10g and 11g

    I want to know with example how to outer join three different tables in Oracle.
    Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!

    Hi,
    897293 wrote:
    I want to know with example how to outer join three different tables in Oracle.The 3rd table comes into the result set the same way the 2nd one did:
    FROM           table_1  t1
    LEFT OUTER JOIN      table_2  t2  ON   ...
    LEFT OUTER JOIN      table_3  t3  ON   ...The join condition(s) for t3 can reference t1, or t2, or both.
    Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!The main manuals all have "What's New" sections near the beginning. For example:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/wnsql.htm#sthref5
    Hoek,
    We've missed you. Welcome back!

  • Getting no result by joining three tables in BMM

    Hi all,
    I have a requirement where I have a fact table and two ailas dimension table.
    Let say fact is w_account_f and dimension ailas dim_w_account_d_trans and dim_w_account_d_sal of w_account_d table
    I have join in physical layer
    w_account_f ----> dim_w_account_d_trans with forgin key join
    w_account_f ----> dim_w_account_d_sal with forgin key join
    In BMM i have join these three table but given content level filter in dimension like
    dim_w_account_d_trans.tans_col = 'active'
    dim_w_account_d_sal.sal > 4000
    when i am trying to pull the report from all three table
    w_account_f, dim_w_account_d_trans, dim_w_account_d_sal
    its not giving any result where as when i trying to pull report with fact any one dimension its giving me result.
    can anyone help me in finding the soulting how to get the data by joining all these three tables.

    Hi,
    Take the physical query with all three tables selected. Run the query in sql developer, remove the joins one by one and check where it fails. Modify the rpd model accordingly.
    Regards,
    Dpka

  • Joining Three Tables with multiple record

    Dear All
    we need some help. We have Three Tables in sqlserver2012
    Master Table
    OrderID       PackageID      CustomerName
    1                          1               Abc
    2                          2                Bcd
    3                          1                xyz
    Child1 Table
    OrderID          ControlName
    1                   Row1COlumn1             (It Means Pant in Red Color is selected by user(relation with Child2 Table))
    1                   Row3Column1             (It Means Gown in Blue Color is selected by user(relation with Child2 Table))
    1                   Row4Column3             (It Means T Shirt in White Color is selected by user(relation with Child2 Table))
    2                    Row1Column2            (It Means Tie in Green Color is selected by user(relation with Child2 Table))
    2                   Row3Column1            (It Means Bow in Red Color is selected by user(relation with Child2 Table))
    Child2 Table
    PackageID      Product      Color1     Color2    Color3
    1                       Pant        Red          Green     Blue    
    1                       Shirt        Blue      Pink    Purple
    1                       Gown         Blue      Black    Yellow
    1                       T Shirt     Red          Green     White
    2                       Tie         Red          Green     White
    2                       Socks       Red          Green     White
    2                       Bow         Red          Green     White
    We want to have result like
    OrderID    PackageID      CustomerName   Pant    Gown  T Shirt     Tie         Bow  
    1                     1                 ABC               Red     Blue    White      x    
          x
                                                                   Blue
    2                      2                 Bcd                 x         x          x
           Green      Red
    I have tried 
    ;with mycte as (
    select  ms.OrderID,ms.PackageID
    ,ms.CustomerName
    , Replace(stuff([ControlName], charindex('Column',ControlName),len(ControlName),''),'Row','')  rowNum 
    ,Replace(stuff([ControlName], 1, charindex('Column',ControlName)-1 ,''),'Column','') columnNum 
    From  child1 c inner join MasterTable ms on c.Orderid=ms.orderid)
    ,mycte1 as (
    select *, row_number() Over(Partition By PackageID Order By Child2ID) rn from child2
    ,mycte2 as (
    Select m.OrderID,m.PackageID, m.CustomerName, m.ColumnNum,  m1.Product 
    --,m1.Color1 , m1.Color2, m1.Color3 
    , Case WHEN ColumnNum= 1 Then Color1 
     WHEN ColumnNum= 1 Then Color1 
      WHEN ColumnNum= 2 Then Color2 
       WHEN ColumnNum= 3 Then Color3 End Colors  
    from mycte m 
    join mycte1 m1 on m.rowNum=m1.rn and m.PackageID=m1.PackageID)
    Select OrderID,PackageID,CustomerName, ISNULL(Max(Case WHen Product='Pant' Then Colors END),'X') as 'Pant'
    , ISNULL(Max(Case WHen Product='Gown' Then Colors END),'X') as 'Gown'
    , ISNULL(Max(Case WHen Product='T Shirt' Then Colors END),'X') as 'T Shirt'
    , ISNULL(Max(Case WHen Product='Tie' Then Colors END),'X') as 'Tie'
    , ISNULL(Max(Case WHen Product='Bow' Then Colors END),'X') as 'Bow'
    FROM mycte2
     Group by OrderID,PackageID, CustomerName
    it works if we have a product in one color only. like if we have pant in red and blue then its showing just first record
    Thanks and Best Regards Umair

    Are you really storing textual values like "Row3Column1" or "Row4Column3"???
    Your model is a mess. Redesign it.. btw, these kind of models are quite complex.
    USE tempdb;
    GO
    CREATE TABLE dbo.Colors
    ColorID INT NOT NULL ,
    ColorName NVARCHAR(255) NOT NULL ,
    CONSTRAINT PK_Colors PRIMARY KEY ( ColorID )
    CREATE TABLE dbo.Products
    ProductID INT NOT NULL ,
    ProductName NVARCHAR(255) NOT NULL ,
    CONSTRAINT PK_Products PRIMARY KEY ( ProductID ) ,
    CONSTRAINT UQ_Products_ProductName UNIQUE ( ProductName )
    CREATE TABLE dbo.Packages
    PackageID INT NOT NULL ,
    CONSTRAINT PK_Packages PRIMARY KEY ( PackageID )
    CREATE TABLE dbo.PackageDetails
    ColorID INT NOT NULL ,
    PackageID INT NOT NULL ,
    ProductID INT NOT NULL ,
    CONSTRAINT PK_PackageDetails PRIMARY KEY ( ColorID, PackageID, ProductID ) ,
    CONSTRAINT FK_PackageDetails_ColorID FOREIGN KEY ( ColorID ) REFERENCES dbo.Colors ( ColorID ) ,
    CONSTRAINT FK_PackageDetails_PackageID FOREIGN KEY ( PackageID ) REFERENCES dbo.Packages ( PackageID ) ,
    CONSTRAINT FK_PackageDetails_ProductID FOREIGN KEY ( ProductID ) REFERENCES dbo.Products ( ProductID )
    CREATE TABLE dbo.Orders
    OrderID INT NOT NULL ,
    CustomerID INT NOT NULL ,
    PackageID INT NOT NULL ,
    CONSTRAINT PK_Orders PRIMARY KEY ( OrderID ) ,
    CONSTRAINT UQ_Orders_CustomerID UNIQUE ( OrderID, PackageID ) ,
    CONSTRAINT FK_Orders_PackageID FOREIGN KEY ( PackageID ) REFERENCES dbo.Packages ( PackageID )
    CREATE TABLE dbo.OrderDetails
    ColorID INT NOT NULL ,
    OrderID INT NOT NULL ,
    PackageID INT NOT NULL ,
    ProductID INT NOT NULL ,
    CONSTRAINT FK_OrderDetails_Orders FOREIGN KEY ( OrderID, PackageID ) REFERENCES dbo.Orders ( OrderID, PackageID ) ,
    CONSTRAINT FK_OrderDetails_PackageDetails FOREIGN KEY ( ColorID, PackageID, ProductID ) REFERENCES dbo.PackageDetails ( ColorID, PackageID, ProductID )
    GO
    INSERT INTO dbo.Colors
    ( ColorID, ColorName )
    VALUES ( 1, 'Red' ),
    ( 2, 'Green' ),
    ( 3, 'Blue' ),
    ( 4, 'Pink' ),
    ( 5, 'Purple' ),
    ( 6, 'Black' ),
    ( 7, 'Yellow' ),
    ( 8, 'White' );
    INSERT INTO dbo.Products
    ( ProductID, ProductName )
    VALUES ( 1, 'Pant' ) ,
    ( 2, 'Shirt' ) ,
    ( 3, 'Gown' ) ,
    ( 4, 'T Shirt' ) ,
    ( 5, 'Tie' ) ,
    ( 6, 'Socks' ) ,
    ( 7, 'Bow' );
    INSERT INTO dbo.Packages
    ( PackageID )
    VALUES ( 1 ),
    ( 2 );
    INSERT INTO dbo.PackageDetails
    ( PackageID, ProductID, ColorID )
    VALUES ( 1, 1, 1 ),
    ( 1, 2, 3 ),
    ( 1, 3, 3 ),
    ( 1, 4, 1 ),
    ( 2, 5, 1 ),
    ( 2, 6, 1 ),
    ( 2, 7, 1 ),
    ( 1, 1, 2 ),
    ( 1, 2, 4 ),
    ( 1, 3, 6 ),
    ( 1, 4, 2 ),
    ( 2, 5, 2 ),
    ( 2, 6, 2 ),
    ( 2, 7, 2 ),
    ( 1, 1, 3 ),
    ( 1, 2, 5 ),
    ( 1, 3, 7 ),
    ( 1, 4, 8 ),
    ( 2, 5, 8 ),
    ( 2, 6, 8 ),
    ( 2, 7, 8 );
    INSERT INTO dbo.Orders
    ( OrderID, PackageID, CustomerID )
    VALUES ( 1, 1, 1 ),
    ( 2, 2, 2 ),
    ( 3, 1, 3 );
    INSERT INTO dbo.OrderDetails
    ( ColorID, OrderID, PackageID, ProductID )
    VALUES ( 1, 1, 1, 1 ),
    ( 3, 1, 1, 3 ),
    ( 8, 1, 1, 4 ),
    ( 2, 2, 2, 5 ),
    ( 1, 2, 2, 7 );
    GO
    SELECT *
    FROM dbo.Orders O
    INNER JOIN dbo.OrderDetails OD ON OD.OrderID = O.OrderID
    INNER JOIN dbo.Products P ON P.ProductID = OD.ProductID
    INNER JOIN dbo.Colors C ON C.ColorID = OD.ColorID;
    GO
    DROP TABLE dbo.OrderDetails;
    DROP TABLE dbo.Orders;
    DROP TABLE dbo.PackageDetails;
    DROP TABLE dbo.Packages;
    DROP TABLE dbo.Products;
    DROP TABLE dbo.Colors;
    GO

  • Joining three tables to get totals on three columns.

    hi gurus,
    i have spent hours and hours to get the desired result with this join query. 98% of the query bring results according to my expectations but for some reasons few results are duplicating. let me give you the structure of my tables than my query and than what i expect it to bring. here we go;
    There are three tables
    *1. SENDER*
    Name Null? Type
    SNAME VARCHAR2(50)
    SPHONE1 NOT NULL VARCHAR2(15)
    SPHONE2 VARCHAR2(15)
    SPHONE3 VARCHAR2(15)
    SCITY VARCHAR2(25)
    SREMARKS VARCHAR2(200)
    IDENTIFICATION VARCHAR2(20)
    ADD1 VARCHAR2(30)
    ADD2 VARCHAR2(30)
    *2. TRANSACTION*
    Name Null? Type
    T_ID NOT NULL NUMBER
    SPHONE1 VARCHAR2(15)
    R_ID NUMBER
    RB_ID VARCHAR2(10)
    TRANSFER_TO VARCHAR2(25)
    TDATE DATE
    SOURCE VARCHAR2(20)
    CURR VARCHAR2(10)
    PAID VARCHAR2(10)
    MOP VARCHAR2(10)
    DOLLAR NUMBER
    RATE NUMBER(5,2)
    RUPPEE NUMBER
    TREM1 VARCHAR2(200)
    TREM2 VARCHAR2(100)
    PPAYMENT VARCHAR2(10)
    PROMISE VARCHAR2(50)
    BALANCE NUMBER
    DOLLAR2 NUMBER
    *3. PAYMENTS*
    Name Null? Type
    PAYMENT_ID NOT NULL NUMBER
    PDATE DATE
    SPHONE1 VARCHAR2(15)
    AMT_PAID NUMBER
    BALANCE NUMBER
    T_ID NUMBER
    QUERY_
    select a.sname, a.sphone1, nvl(sum(b.dollar),0) ORD, nvl(sum(b.dollar2),0) ADV,
    nvl(sum(c.amt_paid),0) Paid
    from sender a, transaction b, payments c
    where a.sphone1 = b.sphone1
    and b.t_id = c.t_id(+)
    and b.paid in ('N','B')
    group by a.sname, a.sphone1
    order by 1
    HERE IS THE RESULT OF THIS QUERY:_
    SNAME SPHONE1 ORD ADV PAID
    Muhammad Atif Ishtiaq 778 889 7195 2150 635 45
    BRIEF DESCRIPTION:*
    We have sender info in SENDER table, when they place order it goes to TRANSACTION table and when they pay it goes into PAYMENTS. some times they make payments in installment of a single order. which i record them in payments with their T_ID (Transaction ID) and this is the problem what i research until now. many customers place multiple orders over a period of time but dont pay and some times pay the orders in installment. i just want to present the whole story in one single row, as i mentioned above under query result. in this example the actual ORD suppose to be $2050 instead and ADV $605. PAID is OK.
    SQL> select t_id, dollar, dollar2 from transaction where paid = 'B' and sphone1 = '778 889 7195';
    T_ID DOLLAR DOLLAR2
    18274 450
    18278 1000 500
    18263 100 30
    18265 100
    18266 100
    18268 100 25
    18269 200 50
    SQL> select t_id, amt_paid from payments
    where t_id in (select t_id from transaction
    where paid = 'B' and sphone1 = '778 889 7195')
    T_ID AMT_PAID
    18263 20
    18263 25
    AND in the end i would like to calculate balance of the columns ((ORD+ADV) - (PAID))
    Any help would be appreciated.
    best regards.
    NOTE: i am running oracle 8 and developer 6i

    try this:
    WITH TRANSACTION AS (select 18274 t_id, 450 dollar, NULL dollar2, '778 889 7195' sphone1 FROM DUAL
                         UNION ALL
                         select 18278 t_id, 1000 dollar, 500 dollar2, '778 889 7195' sphone1 FROM DUAL
                         UNION ALL
                         select 18263 t_id, 100 dollar, 30 dollar2, '778 889 7195' sphone1 FROM DUAL
                         UNION ALL
                         select 18265 t_id, 100 dollar, NULL dollar2, '778 889 7195' sphone1 FROM DUAL
                         UNION ALL
                         select 18266 t_id, 100 dollar, NULL dollar2, '778 889 7195' sphone1 FROM DUAL
                         UNION ALL
                         select 18268 t_id, 100 dollar, 25 dollar2, '778 889 7195' sphone1 FROM DUAL
                         UNION ALL
                         select 18269 t_id, 200 dollar, 50 dollar2, '778 889 7195' sphone1 FROM DUAL
         PAYMENTS AS    (select 18263 t_id, 20 amt_paid FROM DUAL
                         UNION ALL
                         select 18263 t_id, 25 amt_paid FROM DUAL
         SENDER AS      (SELECT 'Muhammad Atif Ishtiaq' SNAME, '778 889 7195' SPHONE1 FROM DUAL
    select a.sname,
           a.sphone1,
           nvl(ORD,0) ORD,
           nvl(ADV,0) ADV,
           nvl(amt_paid,0) Paid
      from sender a,
           (SELECT sphone1,
                   sum(dollar) ord,
                   sum(dollar2) adv
              from transaction b
            GROUP BY sphone1) b,
           (SELECT sphone1,
                   SUM(amt_paid) amt_paid
              FROM payments p,
                   transaction t
             where p.t_id=t.t_id
             GROUP BY sphone1) c
    where a.sphone1 = b.sphone1
    and b.sphone1=c.sphone1(+);

  • Need help with the update queries - joining three tables -

    We have three tables shown below, each with millions of rows;
    And need some updates in here;
    T_CHECK->TOTAL_AMT_PAID should be equal to
    aim00.t_chck_clm_xref->amt_paid + aim01.t_chck_clm_xref->amt_paid;
    Some CHECK_SAK values exist in aim00.t_chck_clm_xref and some exist in aim01.t_chck_clm_xref;
    We tried to update using the queries within PL/SQL shown below:
    Is there a way to make these more effecient?
    SQL> desc aim.t_check;
    Name Null? Type
    CHECK_SAK NOT NULL NUMBER(9)
    TOTAL_AMT_PAID NOT NULL NUMBER(11,2)
    DTE_ISSUE NOT NULL NUMBER(8)
    SQL> desc aim00.t_chck_clm_xref
    Name Null? Type
    CHECK_SAK NOT NULL NUMBER(9)
    AMT_PAID NOT NULL NUMBER(10,2)
    SQL> desc aim01.t_chck_clm_xref
    Name Null? Type
    CHECK_SAK NOT NULL NUMBER(9)
    AMT_PAID NOT NULL NUMBER(10,2)
    create or replace PROCEDURE CHECKSUPDATE IS
    cursor my_cursor is
    select /*+ DRIVING_SITE(t_check) INDEX(t_check) */
    tot, mid, aim.t_check.total_amt_paid from
    (select sum(aim01.t_chck_clm_xref.amt_paid) tot,
    aim01.t_chck_clm_xref.check_sak mid from aim01.t_chck_clm_xref
    where
    not exists (select 'x' from aim00.t_chck_clm_xref
    where aim01.t_chck_clm_xref.check_sak = aim00.t_chck_clm_xref.check_sak
    group by aim01.t_chck_clm_xref.check_sak) TABLE1, aim.t_check
    where aim.t_check.check_sak = table1.mid
    and aim.t_check.total_amt_paid <> tot;
    my_count NUMBER;
    BEGIN
    my_count:=0;
    for my_pos in my_cursor loop
    update aim.t_check a set total_amt_paid=my_pos.tot
    where a.check_sak=my_pos.mid;
    my_count:=my_count+1;
    if (mod(my_count,1000)=0) THEN
    commit;
    end if;
    end loop;
    commit;
    END CHECKSUPDATE;

    >
    SQL> desc t_check;
    Name Null? Type
    CHECK_SAK           NUMBER(9)
    TOTAL_AMT_PAID NUMBER(11,2)
    DTE_ISSUE NUMBER(8)
    SQL> desc t_chck_clm_xref
    Name Null? Type
    CHECK_SAK      NUMBER(9)
    AMT_PAID NUMBER(10,2)
    SQL> desc t_test
    Name Null? Type
    CHECK_SAK NUMBER(9)
    AMT_PAID NUMBER(10,2)
    select check_sak, sum(amt_paid)
    from (
      select check_sak, amt_paid from t_chck_clm_xref
      union all
      select check_sak, amt_paid from t_test
    group by check_sak;and use this query in an UPDATE statement or a MERGE statement, as Tubby suggested, against the T_CHECK table.
    isotope

  • Please help - Joining three tables and get row values into Column. Please help!

    Hi,
    There is a SourceTable1 (Employee) with Columns like EmployeeID,Name,DOB.
    There is a sourcetable2 (EmployeeCode) with columns like EmployeeID,Code,Order.
    There is a source table 3  #EmployeeRegioncode  and its columns are (EmployeeID , RegionCode , [Order] 
    The target table 'EmployeeDetails' has the following details. EmployeeID,Name,DOB,Code1,Code2,Code3,Code4,regioncode1
    regioncode2 ,regioncode3 ,regioncode4 
    The requirement is , the value of the target table columns the Code1,code2,code3 ,code4,code5 values should
    be column 'Code' from Sourcetable2 where its 'Order' column is accordingly. ie) Code1 value should be the 'Code' value where [Order] column =1, and Code2 value should be the 'Code' value where [Order] =2, and so on.
    Same is the case for Source table 3- 'Region code' column also for the columns  regioncode1
    regioncode2 ,regioncode3 ,regioncode4 
    Here is the DDL and Sample date for your ref.
    IF OBJECT_ID('TEMPDB..#Employee') IS NOT NULL DROP TABLE #Employee;
    IF OBJECT_ID('TEMPDB..#EmployeeCode') IS NOT NULL DROP TABLE #EmployeeCode;
    IF OBJECT_ID('TEMPDB..#EmployeeDetails') IS NOT NULL DROP TABLE #EmployeeDetails;
    ---Source1
    CREATE table #Employee 
    (EmployeeID int, Empname varchar(20), DOB date )
    insert into #Employee VALUES (1000,'Sachin','1975-12-12') 
    insert into #Employee VALUES (1001,'Sara','1996-12-10') 
    insert into #Employee  VALUES (1002,'Arjun','2000-12-12')
    ---Source2
    CREATE table #EmployeeCode 
    (EmployeeID int, Code varchar(10), [Order] int)
    insert into #EmployeeCode VALUES (1000,'AA',1) 
    insert into #EmployeeCode VALUES (1000,'BB',2)   
    insert into #EmployeeCode  VALUES (1000,'CC',3)  
    insert into #EmployeeCode VALUES  (1001,'AAA',1)  
    insert into #EmployeeCode  VALUES  (1001,'BBB',2)  
    insert into #EmployeeCode  VALUES  (1001,'CCC',3)  
    insert into #EmployeeCode  VALUES  (1001,'DDD',4)  
    insert into #EmployeeCode  VALUES  (1002,'AAAA',1)  
    insert into #EmployeeCode  VALUES  (1002,'BBBB',2)  
    insert into #EmployeeCode  VALUES  (1002,'CCCC',3)  
    insert into #EmployeeCode  VALUES  (1002,'DDDD',4)  
    insert into #EmployeeCode  VALUES  (1002,'EEEE',5)  
    ---Source tbl 3
    CREATE table #EmployeeRegioncode 
    (EmployeeID int, RegionCode varchar(10), [Order] int)
    insert into #EmployeeRegioncode VALUES (1000,'xx',1) 
    insert into #EmployeeRegioncode VALUES (1000,'yy',2)   
    insert into #EmployeeRegioncode  VALUES (1000,'zz',3)  
    insert into #EmployeeRegioncode VALUES  (1001,'xx',1)  
    insert into #EmployeeRegioncode  VALUES  (1001,'yy',2)  
    insert into #EmployeeRegioncode  VALUES  (1001,'zz',3)  
    insert into #EmployeeRegioncode  VALUES  (1001,'xy',4)  
    insert into #EmployeeRegioncode  VALUES  (1002,'qq',1)  
    insert into #EmployeeRegioncode  VALUES  (1002,'rr',2)  
    insert into #EmployeeRegioncode  VALUES  (1002,'ss',3)  
    ---Target
    Create table #EmployeeDetails
    (EmployeeID int, Code1 varchar(10), Code2 varchar(10),Code3 varchar(10),Code4 varchar(10),Code5 varchar(10) , regioncode1 varchar(10),
    regioncode2 varchar(10),regioncode3 varchar(10),regioncode4 varchar(10))
    insert into #EmployeeDetails  VALUES (1000,'AA','BB','CC','','','xx','yy','zz','')  
    insert into #EmployeeDetails  VALUES (1001,'AAA','BBB','CCC','DDD','','xx','yy','zz','xy')  
    insert into #EmployeeDetails VALUES (1002,'AAAA','BBBB','CCCC','DDDD','EEEE','qq','rr','ss','')  
    SELECT * FROM  #Employee
    SELECT * FROM  #EmployeeCode
    SELECT * FROM  #EmployeeRegioncode
    SELECT * FROM  #EmployeeDetails
    Can you please help me to get the desired /targetoutput?  I have sql server 2008.
    Your help is greatly appreciated.

    select a.EmployeeID,b.code1,b.code2,b.code3,b.code4,b.code5,c.Reg1,c.Reg2,c.Reg3,c.Reg4 from
    #Employee a
    left outer join
    (select EmployeeID,max(case when [Order] =1 then Code else '' end) code1,
    max(case when [Order] =2 then Code else '' end)code2,
    max(case when [Order] =3 then Code else '' end)code3,
    max(case when [Order] =4 then Code else '' end)code4,
    max(case when [Order] =5 then Code else '' end)code5 from #EmployeeCode group by EmployeeID) b
    on a.EmployeeID=b.EmployeeID
    left outer join
    (select EmployeeID,max(case when [Order] =1 then RegionCode else '' end) Reg1,
    max(case when [Order] =2 then RegionCode else '' end)Reg2,
    max(case when [Order] =3 then RegionCode else '' end)Reg3,
    max(case when [Order] =4 then RegionCode else '' end)Reg4 from #EmployeeRegioncode group by EmployeeID) c
    on a.EmployeeID=c.EmployeeID
    Thanks
    Saravana Kumar C

  • Joining three tables to get specific data set

    table1
    id
    seq
    dat
    table2
    id
    seq
    empid
    taxid
    Table3
    empid
    taxid
    I want to find out records That have same id,seq,empid having different taxid column Common to three of the tables .
    Please help me

    Hi,
    There are a lot of different things you could mean.
    Here's how to do one of them:
    SELECT       t2.id,  t2.seq,  t2.empid
    FROM       table2     t2
    JOIN       table1     t1     ON     t2.id        = t1.id
                          AND     t2.seq        = t1.seq
    JOIN       table3     t3     ON     t2.emp_id  = t3.empid
                          AND     t2.taxid   = t3.taxid
    GROUP BY  t2.id,  t2.seq,  t2.empid
    HAVING       COUNT (DISTINCT t2.taxid) > 1
    ;It would help if you posted some sample data (CREATE TABLE and INSERT statements) from all 3 tables, and the results you want from that data.

  • Joining three tables through link tables

    I have three separate tables that are related to each other through two link tables.
    Employees have a many to many relationship with Programs (1 link table)
    Employee + Programs have a many to many relationship with Attributes (The employee attributes depend on the program). This is another link table.
    So, the first link table (emp_prog_lk) has two columns, employee_id and program_id. The second link table has three attributes, employee_id, program_id, and attribute_id.
    The question is, how can I map the Employee object so that I can call getAttributes(Program) and receive the list of attributes for the specified program? Is this even possible without writing custom SQL?
    Thanks.

    How do you want your object model to look? Do you want Employee to simply have a Collection of Attributes? If so, then you're right, I don't think this is possible -- but to me if you'd like this association table between employees and Attributes to have extra info (in this case a Program), then you need to consider and model it in your Object model.
    I.e., when you have a relationship table that has anything other than the PK's of the 2 tables it's relating, then you really need to model that in Java and aren't really able to rely on the java.util.Collection to suffice.
    - Don

  • Joinning of three tables

    hi can u guys plss tell me how to join three tables!! my requirement wants me to do some kind of join on three tables!!
    points promised!! thanx in advance!!

    hi,
    check this sample code
    TABLES : KNA1,KNVV.
    SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-101.
    select-options : p_kunnr like kna1-kunnr.
    SELECTION-SCREEN : END OF BLOCK b1.
    data :BEGIN OF T_KNA1 OCCURS 0,
          KUNNR LIKE KNA1-KUNNR,
          LAND1 LIKE KNA1-LAND1,
          NAME1 LIKE KNA1-NAME1,
          END OF T_KNA1.
    DATA :BEGIN OF T_KNVV OCCURS 0,
          KUNNR LIKE KNA1-KUNNR,
          VKORG LIKE KNA1-VKORG
          VTEWG LIKE KNA1-VTEWG,
          END OF T_KNVV.
    FINAL INTERNAL TABLE
    DATA : BEGIN OF T_FINAL OCCURS 0,
           KUNNR LIKE KNA1-KUNNR,
          LAND1 LIKE KNA1-LAND1,
          NAME1 LIKE KNA1-NAME1,
          VKORG LIKE KNA1-VKORG
          VTEWG LIKE KNA1-VTEWG,
          END OF T_FINAL.
    START-OF-SELECTION
    SELECT KUNNR LAND1 NAME1 FROM KNA1 INTO TABLE T_KNA1 WHERE KUNNR IN P_KUNNR
    IF SY-SUBRC = 0.
    select KUNNR
            VKORG VTEWG
            from KNVV
            into CORRESPONDING FIELDS OF table T_KNVV
            for all entries in T_KNA1
            where KUNNR = T_KNA1-KUNNR.
    ENDIF.
    LOOP AT T_KNA1.
    MOVE T_KNA1-KUNNR TO T_FINAL-KUNNR.
    MOVE T_KNA1-LAND1 TO T_FINAL-LAND1.
    MOVE T_KNA1-NAME1 TO T_FINAL-NAME1.
    READ TABLE T_KNVV WITH KEY KUNNR = T_KNA1-KUNNR.
    IF SY-SUBRC = 0.
    MOVE T_KNVV-VKORG TO T_FINAL-VKORG.
    MOVE T_KNVV-VTEWG TO T_FINAL-VTEWG.
    ENDIF.
    APPEND T_FINAL.
    CLEAR T_FINAL.
    ENDLOOP.
    LOOP AT T_FINAL.
    WRITE: (FIELDS U WANT TO DISPLAY)
    ENDLOOP.
    regards
    siva

  • Left outer join 3 tables with where-statement

    Hi folks,
    I hope you can understand (and maybe solve) my problem.
    Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
    The three table structures are the following:
    table 1 (user)   
    user1 | key
    table 2 (detail)  
    key | ID
    table 3 (header)
    ID | user2                 
    ...and I want to achieve the following structure (as example filled with data):
    user | key | ID
    |-----|----
    xy    | a    | 001
    xy    | b    | #
    z     | b     | #
    The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
    1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
    2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
    I tried this coding:
    SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
      LEFT OUTER JOIN table2 AS b ON akey = bkey )
      LEFT OUTER JOIN table3 AS c ON bID = cID )
      WHERE auser1 = cuser2.
    I would really appreciate your help.
    Regards
    MrclSpdl

    IF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
    select dbfields
    into table itab2
    from dbtab
    for all entries in itab
    where dbfield1 = itab-field1.
    This will get you a second internal table with all the corresponding data for the first selection.  You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation).  Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
    Regards,
    Freek

Maybe you are looking for

  • How to handle exceptions in a Service

    Hi, I'm trying to get the new Service (background thread) stuff working and am close but I have a problem with handling exceptions that are thrown in my Task. Below is my code, does anyone know if I am doing something wrong, or is this just a flaw in

  • Finder can't see external drive

    Whilst trying to set my external drive so that a 'guest' user could not access it, I somehow managed to remove all permissions for myself from that volume. Not being able to access Get Info - Ownership & Permissions, I found an April 07 post from Rob

  • Is it possible to upload a picture from a real estate site?

    Is it possible to upload a picture from a real estate site?

  • OBIEE - LINUX

    Hi I installed OBIEE on linux. Can some one pls let me know the steps how we can deploy/develop projects in OBIEE on linux. Is there any tutorial on how to develop prd in windows and deploy in lunix and chnage the db connections Etc... Thanks in adva

  • Number Range Split from external to internal generation

    Dear Expert, Currently we have various customer account group for which single below number rang 02 is assigned. Client has sub-range slab which assigned to different account group, unfortunately this is setup was not setup in SAP system. Hence whene