Three tables problem

Hi
My information is spread over three (database) tables:
- one master table M with organisation codes
- one detail table D containing the facts
- one lookup table L, which translates the codes of M in something comprehensible.
L also containes several columns which represent a hierarchical structure.
I want to combine information from the lookup table as dimensions with the facts from the detail table without adding any column of the master table. So the master table is basically there to make a 'join' between facts table and lookup table possible.
My difficulty: How do I put columns of D and L together in the Disco table? One is always greyed out unless I put a column of M in as well. Only, I don't want it.
So far I tried to avoid a complex folder because there are a lot of lookup tables and a folder with 50 columns or more doesn't seem a good solution.
Any ideas?
Franziska

Hi,
The easiest way to do this is to add one column from the M table so that you can add columns from the L table. Once you have added a column from the L table you can remove the M column so that you just have columns from D and L.
Hope that helps,
Rod West

Similar Messages

  • Generate a report with three table

    hi Friends,
    i have three table
    1-
    CREATE TABLE "TRANSACTION_DETAILS"
    (     "S_NO" NUMBER,
         "BILL_NO" NUMBER,
         "BILL_DATE" DATE,
         "PARTY_NAME" VARCHAR2(1000),
         "VEHICLE_NO" VARCHAR2(20),
         "ITEM_NAME" VARCHAR2(500),
         "DESCRIPTION" VARCHAR2(4000),
         "QTY" NUMBER,
         "RATE" NUMBER,
         "AMOUNT" NUMBER,
         CONSTRAINT "TRANSACTION_DETAILS_CON" PRIMARY KEY ("S_NO") ENABLE
    2-
    CREATE TABLE "LAB_WORK_DTL"
    (     "ID" NUMBER,
         "BILL_NO" NUMBER,
         "BILL_DATE" DATE,
         "PARTY_NAME" VARCHAR2(1000),
    "VEHICLE_NO" VARCHAR2(20),
         "WORK_DETAIL" VARCHAR2(4000),
         "LABOUR_AMT" NUMBER,      
         CONSTRAINT "LAB_WORK_DTL_PK" PRIMARY KEY ("ID") ENABLE
    3-
    CREATE TABLE "JOB_CARD_DETAILS"
    (     "ID2" NUMBER,
         "BILL_NO" NUMBER,
         "BILL_DATE" DATE,
         "PARTY_NAME" VARCHAR2(1000),
         "VEHICLE_NO" VARCHAR2(20),
         "AMOUNT" NUMBER,
         CONSTRAINT "JOB_CARD_DETAILS_CON" PRIMARY KEY ("ID2") ENABLE
    i want to generate a Report of total amout of bill No Like
    BILL_NO,BILL_DATE,VEHICLE_NO,SUM(AMOUNT) ,SUM(LABOUR_AMT),SUM(AMOUNT)
    I AM USING
    select a.BILL_NO,a.BILL_DATE,a.PARTY_NAME,a.VEHICLE_NO,SUM(a.AMOUNT),SUM(b.LABOUR_AMT),SUM(c.AMOUNT) from TRANSACTION_DETAILS a,LAB_WORK_DTL b,JOB_CARD_DETAILS c where a.PARTY_NAME =b.PARTY_NAME and a.PARTY_NAME=c.PARTY_NAME and a.PARTY_NAME =:P38_PARTY_NAME group by a.bill_no,a.BILL_DATE,a.PARTY_NAME,a.VEHICLE_NO,b.bill_no,b.BILL_DATE,b.PARTY_NAME,b.VEHICLE_NO,c.bill_no,c.BILL_DATE,c.PARTY_NAME,c.VEHICLE_NO
    ACCORDING TO THIS CODE sum of these column SUM(a.AMOUNT),SUM(b.LABOUR_AMT),SUM(c.AMOUNT) are not correct and there are one more problem if BILL_NO is not in LAB_WORK_DTL JOB_CARD_DETAILS these table then result shows NO DATA FOUND but BILL_NO is avalable in
    TRANSACTION_DETAILS this table.
    How can i generate this report .
    Thanks
    Manoj Kaushik

    1-
    CREATE TABLE  "TRANSACTION_DETAILS"
    (     "S_NO" NUMBER,
         "BILL_NO" NUMBER,
         "BILL_DATE" DATE,
         "PARTY_NAME" VARCHAR2(1000),
         "VEHICLE_NO" VARCHAR2(20),
         "ITEM_NAME" VARCHAR2(500),
         "DESCRIPTION" VARCHAR2(4000),
         "QTY" NUMBER,
         "RATE" NUMBER,
         "AMOUNT" NUMBER,
          CONSTRAINT "TRANSACTION_DETAILS_CON" PRIMARY KEY ("S_NO") ENABLE
    2-
    CREATE TABLE  "LAB_WORK_DTL"
    (     "ID" NUMBER,
         "BILL_NO" NUMBER,
         "BILL_DATE" DATE,
         "PARTY_NAME" VARCHAR2(1000),
    "VEHICLE_NO" VARCHAR2(20),
         "WORK_DETAIL" VARCHAR2(4000),
         "LABOUR_AMT" NUMBER,      
          CONSTRAINT "LAB_WORK_DTL_PK" PRIMARY KEY ("ID") ENABLE
    3-
    CREATE TABLE  "JOB_CARD_DETAILS"
    (     "ID2" NUMBER,
         "BILL_NO" NUMBER,
         "BILL_DATE" DATE,
         "PARTY_NAME" VARCHAR2(1000),
         "VEHICLE_NO" VARCHAR2(20),
         "AMOUNT" NUMBER,
          CONSTRAINT "JOB_CARD_DETAILS_CON" PRIMARY KEY ("ID2") ENABLE
    /Can you define the relation between these three tables. I see in your sql you are joining the three table with the column PARTY_NAME. Is that the proper joining condition? Can you explain that.
    And also when you say this
    ACCORDING TO THIS CODE sum of these column SUM(a.AMOUNT),SUM(b.LABOUR_AMT),SUM(c.AMOUNT) are not correct What exactly do you mean. What is not correct? Can you show some sample data.
    And also it would be of great help to all the people here if you format your SQL and use {noformat}{noformat} tag to preserve the format of your code.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Querying three tables.

    hi,
    I am new to sql.
    I am trying to write a query to retrive information from 3 tables but it is not working.
    I need your help.
    Problem:
    when i try to retrive data from two tables using equlaity condition it is working fine.
    SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.column1 = table2.column1;
    this is working fine and retriving 1200 rows
    when i try to use the same condition for checking three tables its not giving correct output.
    SELECT table1.column1, table2.column2 FROM table1, table2, table3 WHERE table1.column1 = table2.column1 AND table1.column1 = table3.column1;
    this is also working fine and retriving 2400 rows instead of 1200 rows..
    My requirement is to get o/p from somr columns of thre tables but the thing is column1 of three tables should match.
    your help is greatly appreciated.

    I am using three tables
    username col. in dba_users should be equal to username col. in test and
    grantee col. in dba_role_privs should be equal to username col. in both test and dba_users
    dba_users and dba_role_privs and test tables.
    desc dba_users
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    USER_ID NOT NULL NUMBER
    PASSWORD VARCHAR2(30)
    ACCOUNT_STATUS NOT NULL VARCHAR2(32)
    LOCK_DATE DATE
    EXPIRY_DATE DATE
    DEFAULT_TABLESPACE NOT NULL VARCHAR2(30)
    TEMPORARY_TABLESPACE NOT NULL VARCHAR2(30)
    CREATED NOT NULL DATE
    PROFILE NOT NULL VARCHAR2(30)
    INITIAL_RSRC_CONSUMER_GROUP VARCHAR2(30)
    EXTERNAL_NAME VARCHAR2(4000)
    desc dba_role_privs
    Name Null? Type
    GRANTEE VARCHAR2(30)
    GRANTED_ROLE NOT NULL VARCHAR2(30)
    ADMIN_OPTION VARCHAR2(3)
    DEFAULT_ROLE VARCHAR2(3)
    desc test
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    TYPE_ID VARCHAR2(2)
    PASSWORD VARCHAR2(30)

  • SQL for join table  problem?

    hi morning,
    my problem also haven find out the solution,can help me solve.
    I got one part of register student to exam,during that part is like that.
    Student Code:________(table3)
    Exam Code:_________(table 3)
    Student Name:________(table 1)
    Exam Name:_________(table 2)
    I can write code call table 3 but when three table join together in part 3,got problem is come out alry....The problem is inside the Student Name & Exam Name.When i use the button for NEXTRECORD to check record,cannot call the student Name & exam Name.
    Thank for help. Because i use sql code to call table 3 to check table1 and table 2 detail ,then retrive that data.
    my code is like that,
    private void cmd_NexRec_RSEActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    int i;
    i=0;
    try{
    String x1,x2;
    x1=(jTextField10.getText()).trim();
    x2=(jTextField11.getText()).trim();
    if (x1.equals("")&& x2.equals("") )
    counter.studentExam="R";
    counter.registerStudentExam="N";
    i++;
    jInternalFrame8.setVisible(false);
    Connection con = getConnection2();
    Statement s = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    ResultSet rs=getStudentExams();
    ResultSet rs1=getCodes();
    ResultSet rs2=getExams();
    String select="select * from studentExamFile a LEFT JOIN {studentData b} ON a.student_code=b.student_code LEFT JOIN {exam c} ON c.exam_code=a.exam_code where student_code='"+ x1 +"' and exam_code='"+ x2 +"'" ;
    // String select ="select * from studentExamFile , exam , studentData where studentExamFile.student_code=studentData.student_code and exam.exam_code=studentExamFile.exam_code ";
    // rs = s.executeQuery(select);
    rs.next();
    StudentExam c=getstudentcode(rs);
    Code c1=getCode(rs1);
    Examcode c2=getexamcode(rs2);
    jTextField12.setText(c.studentcode);
    jTextField13.setText(c.examcode);
    jTextField14.setText(rs.getString("c1.name"));
    jTextField15.setText(rs.getString("c2.ename"));
    // jTextField14.setText(c1.name);
    // jTextField14.setText(c2.ename);
    jLabel16.setText("Record: Review");
    jInternalFrame10.setVisible(true);
    jTextField12.setEnabled(false);
    jTextField13.setEnabled(false);
    //New Line
    jTextField14.requestFocus();
    else
    Connection con = getConnection2();
    Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    String w=(jTextField10.getText()).trim();
    String w2=(jTextField11.getText()).trim();
    //String select= "select * from [studentExamFile] where [student_code]>'" w "'";
    // String select1="select * from [studentExamFile] where [exam_code]>'" w2 "'";
    String select="select * from studentExamFile a LEFT JOIN {studentData b} ON a.student_code=b.student_code LEFT JOIN {exam c} ON c.exam_code=a.exam_code where student_code='"+ x1 +"' and exam_code='"+ x2 +"'" ;
    ResultSet rs;
    rs = s.executeQuery(select);
    // rs = s.executeQuery(select1);
    rs.next();
    if(rs.isFirst())
    counter.registerStudentExam="N";
    jInternalFrame8.setVisible(false);
    jTextField12.setText(rs.getString(1));
    jTextField13.setText(rs.getString(2));
    jLabel16.setText("Record: Review");
    jInternalFrame10.setVisible(true);
    jTextField12.setEnabled(false);
    jTextField13.setEnabled(false);
    //New Line
    jTextField14.requestFocus();
    counter.studentExam="R";
    else
    JOptionPane.showMessageDialog(this,"End of the file ","Infomation",JOptionPane.INFORMATION_MESSAGE);
    }catch(SQLException e)
    System.out.println("Error");
    //jTextField3.requestFocus();
    }

    thanks for reply.
    i think my problem is in connection to database .
    String sql="select studentData.student_name, exam.exam_name from studentData,exam,studentExamFile where studentData.student_code=studentExamFile.student_code and exam.exam_code=studentExamFile.exam_code ";
                    // String sql="select studentData.student_name , exam.exam_name from studentExamFile  LEFT JOIN { studentData }  ON studentExamFile.student_code=studentData.student_code LEFT JOIN { exam }  ON exam.exam_code=studentExamFile.exam_code ";
                     Connection con = getConnection();
                     Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                     Connection con2 = getConnection();
                     Statement s3 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                     System.out.println("error");//my problem inside here....help me
                     rs3=s.executeQuery(sql);
                     rs3=s3.executeQuery(sql);
                     rs3.next();
                     String s1,s2;
                     s1=rs3.getString(1);//maybe me dunno how to convert the sql data...
                     s2=rs3.getString(2);
                     rs.next();
                     rs2.next();
                    // rs3.next();
                     Code c=getCode(rs);
                     Examcode c2=getexamcode(rs2);
                     StudentExam c3=getstudentcode(rs3);
                     jTextField12.setText(c3.studentcode);
                     jTextField13.setText(c3.examcode);
                    // jTextField14.setText(rs.getString("c.name")); 
                     //jTextField15.setText(rs.getString("c2.ename"));
                     jTextField14.setText(s1); 
                     jTextField15.setText(s2);
                     jLabel16.setText("Record: Review");
                     jInternalFrame10.setVisible(true);
                     jTextField12.setEnabled(false);
                     //New Line
                     jTextField14.requestFocus();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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

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

  • Selecting data from three tables

    Hi Every one...
    I have three tables, Tbl_FlData, Tbl_Flsubdata,Tbl_OutDirection_Dtl, in these tables the common columns are OUTNO, OUTYEAR. When I am trying to pull data from two tables Tbl_Fldata, Tbl_OutDirection_Dtl by using below query I am getting exact output what i want.
    SELECT Tbl_FLData.OUTNO, Tbl_FLData.OUTHDATE,Tbl_OutDirection_Dtl.OTSERNO FROM Tbl_FLData INNER JOIN Tbl_OutDirection_Dtl ON Tbl_FLData.OUTYEAR = Tbl_OutDirection_Dtl.OUTYEAR AND Tbl_FLData.OUTNO = Tbl_OutDirection_Dtl.OUTNO.
    But the problem is, when I am trying to pull a column from Tbl_FlSubdata.Remarks the out put is coming but the records are duplicating.
    The fields of the tables are
    Tbl_FlData: OUTNO, OUTYEAR, OUTHDATE, SUBJECT,USERDEPTCODE, FDEPTCODE, SENDHDATE, REPLYINDAYS, EXPECTEDHDATE, UD_UID
    Tbl_FLSUBDATA: OUTNO, OUTYEAR, OTSSERNO, SEQNO, EMPCODE, SEQHDATE, REMARKS, UD_UID
    Tbl_OutDirectionDtl : OUTNO, OUTYEAR, OTSERNO, DI_Code, REPLYHDATA, INNO, INHDATE, IN_UD_UID, IN_REMARKS.
    Please help me in this issue.

    Hi,
    Try something like this.
    SELECT distinct Tbl_FLData.OUTNO,
    Tbl_FLData.OUTHDATE,
    Tbl_FLSUBDATA.OTSSERNO
    Tbl_OutDirection_Dtl.OTSERNO
    FROM Tbl_FLData, Tbl_FLSUBDATA, Tbl_OutDirection_Dtl
    where Tbl_FLSUBDATA.OUTNO = Tbl_FLData.OUTNO(+)
    and Tbl_OutDirection_Dtl.OUTNO = Tbl_FLData.OUTNO(+)
    order by Tbl_FLData.OUTNO;
    considering Tbl_FLData as the master table. If there are any other unique fields like "out_no" include it a way as above after "where" with a (+) join and see if you still get duplicates.

  • Fetch the data from three tables

    hi
    i have three table HR,plan ,voidplan
    HR table
    rep_id name
    1111 shyam
    2222 kavi
    3333 snaga
    PLAN table
    id rep_id name status
    1 1111 shyam approved
    2 2222 kavi pending
    VOID PLAN table
    id rep_id name status
    1 1111 shaym approved
    i got the row which is same in two table(HR and PLAN) using the query
    select rep_id from plan p,hr h where h.rep_id=p.rep_id and status='approved'
    so the output is
    rep_id
    1111
    now i need the solution to retrieve the rep from voidplan+plan table
    the result should be like this
    rep_id
    1111(from plan and hr)
    1111(void plan)
    please help me to solve this problem
    regards,
    vally.s

    how about UNION ALL
    select rep_id from plan p,hr h where h.rep_id=p.rep_id and status='approved'
    union all
    select rep_id from void_plan
    this will get only the rows that join and then ALL rows from void_plan (but I suspect this isn't what you want?)
    maybe you only want rows from void_plan that are returned from the first query
    select rep_id from void_plan v
    where v.rep_id in (select rep_id from plan p,hr h where h.rep_id=p.rep_id and status='approved'
    )

  • Fetching data from three tables.

    Hi All,
    I am having three tables company(com_id(PK),com_name),
    contact(contact_id(PK),com_id(FK),first_name,email),
    location(loc_id(PK),com_id(FK),country).
    I need a query to retrieve the first name,email,com_name and country.
    I used:
    select contact.first_name,contact.email,company.com_name,m.country from contact
    LEFT JOIN location m ON contact.com_id=m.com_id
    LEFT JOIN company c ON contact.com_id=c.com_id
    but its returning duplicate rows.
    I am new to this .Please tell me how to solve this problem.
    thanks,

    Jeeth wrote:
    Hi
    Thanks to all for the reply..
    I am using Oracle 10g
    Version:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - ProductionThat says you're uising Oracle 11 (11.2.0.1.0 to be precise), not 10.
    ... And the LOCATION Table containing:
    COM_ID     ADDRESS_ID COUNTRY
    28     1265     United States
    28     1266     United States
    381     381     United States
    610     1873     United States
    864     1586     United States
    869     870     United States
    2414     2662     United StatesPost CREATE TABLE and INSERT statments for your sample data.
    It helps if you explain what the data means. For example, this problem seems to hinge on location.com_id not being unique. What does each row, and each column, in the location table represent? What does each row in the output represent?
    Tried the Query:
    select d.first_name, d.email ,c.com_name , m.country from company c,contact d,location m
    where c.com_id=d.com_id and c.com_id=m.com_id
    I got the result: The second row is repeating:
    Alexander     [email protected]     JPMorgan Chase &amp; Co. (KEY ACCOUNT)     United States
    Alexander     [email protected]     ADP, Inc.      United States
    Alexander     [email protected]     ADP, Inc.      United States
    Alfred     [email protected]     Perficient Inc.     United States
    Allan     [email protected]     Progressive Insurance     United States
    Linda      [email protected]     Principal Financial Group, Inc.     United States
    Alycia     [email protected]     Emerson Electric Co. (KEY ACCOUNT)     United States
    Want output like:
    Alexander     [email protected]     JPMorgan Chase &amp; Co. (KEY ACCOUNT)     United States
    Alexander     [email protected]     ADP, Inc.      United States
    Alfred     [email protected]     Perficient Inc.     United States
    Allan     [email protected]     Progressive Insurance     United States
    Linda      [email protected]     Principal Financial Group, Inc.     United States
    Alycia     [email protected]     Emerson Electric Co. (KEY ACCOUNT)     United States
    Why do you want that ouptut, and not the output that you're originally getting?
    What output would you want if the part you were displaying were different on each row. For example, if we add a row like this to the sample data:
    COM_ID     ADDRESS_ID     COUNTRY
    2414     2663          MexicoThee are many different reasons why you could want the output you do. Each one has a different solution, that would produce different results with different data. You need to explain what you want to do, then someone can help you find a way to code it.
    The simplest way is to say SELECT DISTINCT . That happens to get the right results with the given sample data.

  • 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(+);

  • Join of thre tables - index VLPMA, LIPS, VBUP

    Hello,
    I woud like to ask you about help. I have to do performance tuning of one program wich runs very long. I noticed, that the biggest problem is in join of three tables LIKP, LIPS and VBUP.  I replaced original table LIKP by index table VLPMA and it helped  - mainly when a material is filled in on select-option s_matnr. But the run is still very long. DO you have any idea what more could I do with the select? Ist there any index table similar to lips?
    select lipslgort vlpmavbeln vlpmaposnr vlpmamatnr vlpma~kunnr
            lipslgmng lipsmeins into table ilips
            from vlpma inner join vbup on vbupvbeln eq vlpmavbeln and
                                         vbupposnr eq vlpmaposnr
                      inner join lips on vlpmavbeln eq lipsvbeln and
                                         vlpmaposnr eq lipsposnr
             where vlpma~matnr in s_matnr and
                   lips~lgort in s_lgort and
                   vbup~wbsta ne 'C' and
                   vbup~kosta ne 'C' .
    Thanks a lot
    Miloslav Pudil

    Since VBUP is not in the list of selected fields, it doesn't need to be included in the join. Instead, it can be in an EXISTS subquery in the WHERE clause. This is logically the same but the join is on two tables only. Also incorporating the other idea from Dave L. of not using NOT should help further.
    select lips~lgort vlpma~vbeln vlpma~posnr vlpma~matnr vlpma~kunnr lips~lgmng lips~meins
    into table ilips
    from vlpma
       inner join lips on vlpma~vbeln eq lips~vbeln and vlpma~posnr eq lips~posnr
    where vlpma~matnr in s_matnr
       and  lips~lgort in s_lgort
       and EXISTS ( SELECT *
                              FROM VBUP
                              WHERE vbeln eq vlpma~vbeln
                                    and posnr eq vlpma~posnr
                                    and wbsta IN (' ', 'A', 'B')
                                    and kosta IN (' ', 'A', 'B') ).
    Edited by: Erik Peterson on Dec 1, 2009 9:05 AM

  • Report using three tables on group basis

    Hi,
    I wish to know a clue for the follwing report among three tables either using join or sub-query or PL/SQL Script as per the below desired output.
    Top 10 games by uniques / by volume
    It should produce something like this:
    Game     Uniques     Volumes     Game Start     Game End     Mins on Air     
    Top 5 movies beginning with "D"     2734     7924     9/24/06 9:59 PM     9/24/06 10:41 PM     42     
    Top 5 One Hit Wonders     2355     6471     9/24/06 9:07 PM     9/24/06 9:48 PM     41     
    Things you find in The Kitchen     1336     3600     9/24/06 10:41 PM     9/24/06 10:59 PM     18     
    Twisted Title Men in Black     770     1435     9/24/06 9:53 PM     9/24/06 9:59 PM     6     
    Anagram Lance Armstrong     884     1350     9/24/06 9:48 PM     9/24/06 9:53 PM     5     
    A.Bucks Jack and Jill...     593     824     9/24/06 8:59 PM     9/24/06 9:04 PM     4     
    Missing link ANY101     649     815     9/24/06 9:04 PM     9/24/06 9:07 PM     3     
    Parameters should be startDate and endDate.
    This query can be obtained from using the following tables: Calls, Games, Events, Event_Types
    Calls have a timestamp.
    Every game has event, such as start game or end game (see Event_Types), with its timestamp
    Volumes: Number of calls received for each game between start game date and end date
    Uniques: Unique Number of calls received for each game between start game date and end date
    (distinct cli)
    Mins on air: differences between start call and end call
    Relationship:
    The ID column from games table and game_id from events table is common.
    Assume if the event type id is 2 then it starts game and if 3 then game ends. Other type is irrelevant for this query.
    The id from event_type is mentioned in another table event_types as master with description. But it is not required to establish relationship with this table. As this code ( 2 or 3) is alredy availbel with event_type_id in the events table.
    Please assume the CLI number as dummy data.
    I have provided the structure and query to generate tables and populate testing data to sort out this issue at the earliest.
    I tried to perform this query but I wish to compare the result with the script given by experts as I’m not a core developer.
    1) desc calls
    Name Null? Type
    CLI NOT NULL VARCHAR2(255)
    CALL_DATE NOT NULL TIMESTAMP(6)
    insert into values('&CLI','&call_date')
    select substr(CLI,1,10),substr(call_date,1,22) from calls
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0662740929 22-SEP-06 05.22.44.123
    0662740973 22-SEP-06 05.22.47.123
    0662740956 22-SEP-06 05.22.46.123
    0662740980 22-SEP-06 05.22.47.123
    0662740936 09-MAY-06 05.22.44.123
    0762740954 22-SEP-06 05.22.45.123
    0762740936 09-MAY-06 05.22.47.123
    0762740921 22-SEP-06 05.22.44.123
    0113456789 22-SEP-06 05.47.04.082
    0987654321 22-SEP-06 06.16.29.727
    0 22-SEP-06 06.17.28.141
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0123456789 09-MAY-06 06.27.51.224
    0112740929 22-SEP-06 06.28.43.398
    0123456789 09-MAY-06 06.30.10.830
    0044791475 24-SEP-06 04.38.08.564
    0044791475 24-SEP-06 04.40.05.777
    0123456789 24-SEP-06 05.32.22.267
    0147258369 24-SEP-06 05.34.25.652
    0852147963 24-SEP-06 05.52.56.992
    0123456789 25-SEP-06 01.34.17.157
    0683379112 25-SEP-06 01.35.19.461
    0 25-SEP-06 03.09.12.347
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0141411683 25-SEP-06 03.21.07.402
    0141411683 25-SEP-06 03.21.38.519
    0618769562 02-JUN-06 03.22.12.807
    0123456789 02-JUN-06 03.24.11.387
    0 25-SEP-06 03.25.13.152
    0141412179 25-SEP-06 03.25.38.424
    0123456789 02-JUN-06 03.26.57.687
    0607069617 02-JUN-06 03.27.02.720
    0014141168 26-SEP-06 03.30.55.290
    0618769562 25-SEP-06 03.31.21.141
    0141411683 25-SEP-06 03.31.45.952
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0607069617 25-SEP-06 03.32.14.542
    0618769562 25-SEP-06 03.32.30.433
    0 25-SEP-06 03.32.43.292
    0141412179 25-SEP-06 03.33.07.166
    0 25-SEP-06 03.33.56.086
    0 25-SEP-06 03.34.03.918
    0123456789 26-SEP-06 03.34.21.193
    0 25-SEP-06 03.34.25.484
    0 25-SEP-06 03.34.39.126
    0 25-SEP-06 03.34.40.354
    0 25-SEP-06 03.34.51.231
    2)
    SQL> desc events
    Name Null? Type
    EVENT_TYPE_ID NOT NULL NUMBER(19)
    EVENT_DATE NOT NULL TIMESTAMP(6)
    GAME_ID NUMBER(19)
    insert into events values ('&EVENT_TYPE_ID','&EVENT_DATE',&GAME_ID')
    SQL> select substr(event_type_id,1,10),substr(event_date,1,20),substr(game_id,1,10) from events where game_id in (1918,1919,1920,1939,1958,1979,1999,2018,2040,2041,2061)
    SUBSTR(EVE SUBSTR(EVENT_DATE,1, SUBSTR(GAM
    3 26-APR-06 06.11.50.8 1939
    4 26-APR-06 06.12.05.6 1939
    5 26-APR-06 06.16.13.5 1939
    3 09-MAY-06 06.18.59.7 1920
    4 09-MAY-06 06.22.43.7 1920
    3 12-MAY-06 04.24.46.2 1920
    4 12-MAY-06 04.46.22.5 1920
    3 12-MAY-06 04.29.07.4 1920
    4 12-MAY-06 04.39.31.1 1920
    3 12-MAY-06 04.29.35.3 1920
    4 12-MAY-06 04.30.02.8 1920
    SUBSTR(EVE SUBSTR(EVENT_DATE,1, SUBSTR(GAM
    3 26-SEP-06 12.19.27.6 1958
    4 26-SEP-06 12.29.37.9 1958
    5 01-JUN-06 12.26.37.2 1958
    3 02-JUN-06 11.53.49.0 1979
    6 02-JUN-06 11.54.00.5 1979
    4 02-JUN-06 11.54.55.5 1979
    3 02-JUN-06 11.55.03.7 1979
    4 02-JUN-06 11.57.40.7 1979
    3 02-JUN-06 11.57.43.5 1979
    4 02-JUN-06 11.59.47.2 1979
    3 14-SEP-06 02.24.13.8 1999
    SUBSTR(EVE SUBSTR(EVENT_DATE,1, SUBSTR(GAM
    4 14-SEP-06 02.55.18.7 1999
    3 14-SEP-06 06.44.40.1 1999
    4 14-SEP-06 06.52.57.9 1999
    3 22-SEP-06 04.05.09.5 2018
    4 22-SEP-06 05.24.14.7 2018
    5 22-SEP-06 05.24.25.0 2018
    4 24-SEP-06 03.17.54.8 2018
    3 24-SEP-06 03.19.00.1 2018
    3) INSERT INTO games VALUES ('&ID'.'&NAME')
    SQL> desc games
    Name Null? Type
    ID NOT NULL NUMBER(19)
    NAME NOT NULL VARCHAR2(255)
    select substr(id,1,10),substr(name,1,25) from games;
    SUBSTR(ID, SUBSTR(NAME,1,25)
    1918 Copy of QN27030628
    1919 Copy of Copy of QN0104061
    1920 Copy of Copy of Copy of Q
    1939 Alex Game 8
    1958 QN27030628 Lee
    1979 Copy of QN01040611 9
    1999 Ale's Game
    2018 TF1 Game test 1
    2040 Test Game TF1sarah
    2041 BTAgilemedia Game Test
    2061 Copy of Copy of QN0104060
    Your help would be highly appreciated.
    Thanks
    Jayesh

    Hi,
    I am sending herewith SQL statement for populating data into the concern tables
    To make easier for further testing your script.
    insert into calls values (0772740929, 22-SEP-06 05.22.44.123)
    insert into calls values (0882740929, 22-SEP-06 05.22.44.123)
    insert into calls values (0772740929, 25-SEP-06 05.22.44.123)
    insert into calls values (0662740929, 27-SEP-06 05.22.44.123)
    insert into calls values (0452740929, 22-SEP-06 05.22.44.123)
    insert into calls values (0992740929, 24-SEP-06 05.22.44.123)
    insert into calls values (0992740929, 26-SEP-06 05.22.44.123)
    insert into events values (3, 22-SEP-06 05.22.44.123,1918)
    insert into events values (4, 22-SEP-06 05.32.44.123,1918)
    insert into events values (3, 24-SEP-06 05.22.44,1920)
    insert into events values (4, 24-SEP-06 05.42.44,1920)
    insert into events values (3, 26-SEP-06 05.22.44,1958)
    insert into events values (4, 26-SEP-06 05.52.44,1958)
    Insert into games values (1918,’ Copy of QN27030628’)
    Insert into games values (1920,’ Test Game TF1sarah’)
    Insert into games values (1958,’ Test Car Race’)
    Thanks
    jayesh

  • How can i get all the records from three tables(not common records)

    Hi
    I have four base tables at R/3-Side. And i need to extract them from R/3-Side.
    And i dont have any standard extractor for these tables .
    If i create a 'View' on top of these tables. Then it will give only commom records among the three tables.
    But i want all the records from three base tables (not only common).
    So how can i get the all records from three tables. please let me know
    kumar

    You can create separate 3 datasources for three tables and extract data to BW. There you can implement business login to build relation between this data.

  • How can i Delete the data from three tables at a time  using same key.

    I am New to Oracle ADF, I have a Requirement Like these, I have three tables like Employee,Salaries,Teams all of these are having one common EmpNo as common attribute, I have Search form these will return the all the employees related to that search query, when i click on Delete button the particular employe Data should delete from all the three tables based on the EmpNo.
    Any Help is appreciable..

    1) The easiest way is to mark the foreign key constraints from SALARIES to EMPLOYEES and from TEAMS to EMPLOYEES as ON DELETE CASCADE. The DB server will then delete the necessary rows whenever you delete an employee row.
    2) Another way is to implement a Before-Delete-Row DB trigger on the EMPLOYEES table where you can delete the related rows in the other tables (have in mind, that if you have foreign keys you may get a Mutating Table Exception, so this approach might be not very good).
    3) An ADF way is to implement a custom EntityImpl class for the Employee entity and to override the remove() method where you can lookup the related TeamMember and Salary entities (through EntityAssoc accessors) and invoke their remove() methods too.
    4) Another ADF way is to implement a custom EntityImpl class for the Employee entity and to override the doDML() method where you can delete the necessary rows in SALARIES and TEAMS tables through JDBC calls whenever a DELETE operation is being performed on the underlying Employee entity.
    Dimitar

  • Rectifications of different sizes for all the three table lines in footer.

    Hi friendz,
                    i am working in ecc6 system(smartforms).
                    i am using 3 table lines in the footer one for total, the second one for tax calculation, and the third one for the grand total.
    But in the output screen display - the total, tax and grand total(in different table lines) are displayed with different heights, which gives unprofessional look for the form.
    i want all the table lines in the footer to display with equal heights.

    Hi,
    first you create LTYPE follow below sequence
    Go table tab--> details tab--->give suitable heights for ltype
    next go to FOOTER in the main window
    create three table lines under footer like
    FOOTER1
    FOOTER2
    FOOTER3
    for three table lines we need to assign line type LTYPE
    Go FOOTER1 ---> output options -
    > give LTYPE.
         FOOTER2 ---> output options -
    > give LTYPE.
         FOOTER3 ---> output options -
    > give LTYPE.
    reward points if helpful.
    Regards,
    Bhupal.
    Edited by: bhupal reddy on Jul 22, 2008 11:55 AM

Maybe you are looking for

  • How to find name for a query

    i want to know one thing how the name for the report is made. Transaction code      ZPNL_TESTDEMO Package               ZDEV Transaction text      FGI3 P&L REPORT Transaction        START_REPORT D_SREPOVARI-REPORTTYPE = RE D_SREPOVARI-REPORT D_SREPOV

  • Duplicate control label preventing creation of unit test using UTF

    Hello Everyone,                    I was trying to create a unit test for a VI using the unit test framework (evaluation version) to try out this tool.  I have two questions regarding that. 1. Several sub-VIs are called by this VI. I wanted to create

  • Ipad 1 charging issues

    When charger is plugged in it says charging not supported! Is it charger? Ipad1?

  • Standby Database problem (10g)

    Dear Oracle Experts, I have primary and physical standby instance running. Due to whatever reason, the server running the standby instance is restarted. After the standby instance restart, I have observed that 2 archivelogs that appear in primary ins

  • How to clone data with in Table with dynamic 'n' number of columns

    Hi All, I've a table with syntax, create table Temp (id number primary key, name varchar2(10), partner varchar2(10), info varchar2(20)); And with data like insert itno temp values (sequence.nextval, 'test', 'p1', 'info for p1'); insert into temp valu