How to join 5 different tables using SQL to make it to a flat file structur

I am trying to load five differnt tables into one flat file structure table without cartesian product.
I have five different tables Jobplan, Jobtask(JT), Joblabor(JL), Jobmaterial(JM) and Jpsequence(JS) and the target table as has all the five tables as one table.
The data i have here is something like this.
jobplan = 1record
jobtask = 5 records
joblabor = 2 records
jobmaterial = 1 record
jpsequence = 3 records
The output has to be like this.
JPNUM     DESCRIPTION     LOCATION     JT_JPNUM     JT_TASK     JL_JPNUM     JL_labor     JM_JPNUM     JM_MATERIAL     JS_JPNUM     JS_SEQUENCE
1001     Test Jobplan     USA     NULL     NULL     NULL     NULL     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     1001     10     NULL     NULL     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     1001     20     NULL     NULL     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     1001     30     NULL     NULL     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     1001     40     NULL     NULL     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     1001     50     NULL     NULL     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     NULL     NULL     1001     Sam     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     NULL     NULL     1001     Mike     NULL     NULL     NULL     NULL
1001     Test Jobplan     USA     NULL     NULL     NULL     NULL     1001     Hammer     NULL     NULL
1001     Test Jobplan     USA     NULL     NULL     NULL     NULL     NULL     NULL     1001     1
1001     Test Jobplan     USA     NULL     NULL     NULL     NULL     NULL     NULL     1001     2
1001     Test Jobplan     USA     NULL     NULL     NULL     NULL     NULL     NULL     1001     3
Please help me out with this issue.
Thanks,
Siva
Edited by: 931144 on Apr 30, 2012 11:35 AM

Hope below helps you
CREATE TABLE JOBPLAN
( JPNUM NUMBER,
  DESCRIPTION VARCHAR2(100)
INSERT INTO JOBPLAN VALUES(1001,'Test Jobplan');
CREATE TABLE JOBTASK
( LOCATION VARCHAR2(10),
  JT_JPNUM NUMBER,
  JT_TASK  NUMBER
INSERT INTO JOBTASK VALUES('USA',1001,10);
INSERT INTO JOBTASK VALUES('USA',1001,20);
INSERT INTO JOBTASK VALUES('USA',1001,30);
INSERT INTO JOBTASK VALUES('USA',1001,40);
INSERT INTO JOBTASK VALUES('USA',1001,50);
CREATE TABLE JOBLABOR
( JL_JPNUM NUMBER,
  JL_LABOR VARCHAR2(10)
INSERT INTO JOBLABOR VALUES(1001,'Sam');
INSERT INTO JOBLABOR VALUES(1001,'Mike');
CREATE TABLE JOBMATERIAL
( JM_JPNUM    NUMBER,
  JM_MATERIAL VARCHAR2(10)
INSERT INTO JOBMATERIAL VALUES(1001,'Hammer');
CREATE TABLE JOBSEQUENCE
( JS_JPNUM    NUMBER,
  JS_SEQUENCE NUMBER
INSERT INTO JOBSEQUENCE VALUES(1001,1);
INSERT INTO JOBSEQUENCE VALUES(1001,2);
INSERT INTO JOBSEQUENCE VALUES(1001,3);
SELECT   JP.JPNUM        AS JPNUM       ,
         JP.DESCRIPTION  AS DESCRIPTION ,
         NULL            AS LOCATION    ,
         NULL            AS JT_JPNUM    ,
         NULL            AS JT_TASK     ,
         NULL            AS JL_JPNUM    ,
         NULL            AS JL_labor    ,
         NULL            AS JM_JPNUM    ,
         NULL            AS JM_MATERIAL ,
         NULL            AS JS_JPNUM    ,
         NULL            AS JS_SEQUENCE
FROM JOBPLAN JP
UNION ALL
SELECT   JP.JPNUM        AS JPNUM       ,
         JP.DESCRIPTION  AS DESCRIPTION ,
         JT.LOCATION     AS LOCATION    ,
         JT.JT_JPNUM     AS JT_JPNUM    ,
         JT.JT_TASK      AS JT_TASK     ,
         NULL            AS JL_JPNUM    ,
         NULL            AS JL_labor    ,
         NULL            AS JM_JPNUM    ,
         NULL            AS JM_MATERIAL ,
         NULL            AS JS_JPNUM    ,
         NULL            AS JS_SEQUENCE
FROM JOBPLAN JP, JOBTASK JT
UNION ALL
SELECT   JP.JPNUM        AS JPNUM       ,
         JP.DESCRIPTION  AS DESCRIPTION ,
         NULL            AS LOCATION    ,
         NULL            AS JT_JPNUM    ,
         NULL            AS JT_TASK     ,
         JL.JL_JPNUM     AS JL_JPNUM    ,
         JL.JL_labor     AS JL_labor    ,
         NULL            AS JM_JPNUM    ,
         NULL            AS JM_MATERIAL ,
         NULL            AS JS_JPNUM    ,
         NULL            AS JS_SEQUENCE
FROM JOBPLAN JP, JOBLABOR JL
UNION ALL
SELECT   JP.JPNUM        AS JPNUM       ,
         JP.DESCRIPTION  AS DESCRIPTION ,
         NULL            AS LOCATION    ,
         NULL            AS JT_JPNUM    ,
         NULL            AS JT_TASK     ,
         NULL            AS JL_JPNUM    ,
         NULL            AS JL_labor    ,
         JM.JM_JPNUM     AS JM_JPNUM    ,
         JM.JM_MATERIAL  AS JM_MATERIAL ,
         NULL            AS JS_JPNUM    ,
         NULL            AS JS_SEQUENCE
FROM JOBPLAN JP, JOBMATERIAL JM
UNION ALL
SELECT   JP.JPNUM        AS JPNUM       ,
         JP.DESCRIPTION  AS DESCRIPTION ,
         NULL            AS LOCATION    ,
         NULL            AS JT_JPNUM    ,
         NULL            AS JT_TASK     ,
         NULL            AS JL_JPNUM    ,
         NULL            AS JL_labor    ,
         NULL            AS JM_JPNUM    ,
         NULL            AS JM_MATERIAL ,
         JS.JS_JPNUM     AS JS_JPNUM    ,
         JS.JS_SEQUENCE  AS JS_SEQUENCE
FROM JOBPLAN JP, JOBSEQUENCE JS;
     JPNUM DESCRIPTION     LOCATION      JT_JPNUM    JT_TASK   JL_JPNUM JL_LABOR     JM_JPNUM JM_MATERIA   JS_JPNUM JS_SEQUENCE
      1001 Test Jobplan    NULL       NULL        NULL       NULL       NULL       NULL       NULL    NULL          NULL
      1001 Test Jobplan    USA        1001        10         NULL       NULL       NULL       NULL    NULL          NULL
      1001 Test Jobplan    USA        1001        20         NULL       NULL       NULL       NULL    NULL          NULL
      1001 Test Jobplan    USA        1001        30         NULL       NULL       NULL       NULL    NULL          NULL
      1001 Test Jobplan    USA        1001        40         NULL       NULL       NULL       NULL    NULL          NULL
      1001 Test Jobplan    USA        1001        50         NULL       NULL       NULL       NULL    NULL          NULL
      1001 Test Jobplan    NULL       NULL        NULL       1001       Sam        NULL       NULL    NULL          NULL
      1001 Test Jobplan    NULL       NULL        NULL       1001       Mike       NULL       NULL    NULL          NULL
      1001 Test Jobplan    NULL       NULL        NULL       NULL       NULL       1001       Hammer  NULL          NULL
      1001 Test Jobplan    NULL       NULL        NULL       NULL       NULL       NULL       NULL    1001          1
      1001 Test Jobplan    NULL       NULL        NULL       NULL       NULL       NULL       NULL    1001          2
      1001 Test Jobplan    NULL       NULL        NULL       NULL       NULL       NULL       NULL    1001          3
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to join two tables using EJB-QL

    Hi There,
    How to join tables using EJB-QL ?
    Thanks.
    Edited by: vamseebobby on Nov 6, 2007 8:12 AM

    You might try
    SELECT b.entity2property FROM Entity1 a JOIN a.entity2 b
    for example, to retrieve players names, from a Players table, that belong to the team 'My Team' in the Teams table
    SELECT b.playerName FROM Teams a JOIN a.players b WHERE a.teamName = 'My Team'

  • How to view /SAPAPO/ tables using SQL Studio question

    Hi,
    This is for Livecache 7.4 on AIX.
    I have installed a SQL Studio 7.6. When I logged using SUPERDBA/admin, I can only see tables owned by SUPERDBA, SYS, and DOMAIN.
    I cannot see any tables owned by SAP<LC Name>. I want to see details about table e.g. /SAPAPO/ORDKEY, which is owed by SAP<LC Name>.
    Is it possible to see it using SQL Studio?
    Please let me know if anybody has any idea about it.
    Regards.
    Sume.

    Hello Sume,
    If you would like to see details about table e.g. /SAPAPO/ORDKEY.
    =>
      Did you check the owner of this table?
    => You could check, for example, in LC10 -> liveCache:Monitoring
    -> Problem Analysis -> Tables/Views/Synonyms ->
       Database Object Schema           SAPLCT
       Name of Database Object          *
       < execute >
       & review if the table /SAPAPO/ORDKEY is listed.
    => If the table is listed, you should be able to run the select statement as SAPLCT user on this table.
    If you are sure that you was using the SAPLCT user, please
    Check if this user has application tables:
    < May be the password was changed from the default sap for the
    Standard liveCache user, you should know it. >
    dbmcli -d LCT -u control,control
    dbmcli on LCT>sql_connect SAPLCT,sap
    dbmcli on LCT> sql_execute select * from users
    dbmcli on LCT> sql_execute select * from users
    < I would like to see what DBA users you have in liveCche &
      when the SAPLCT user was created. >
    dbmcli on LCT>sql_execute select tablename from tables where owner='SAPLCT'
    < If the SAPLCT is the owner of the liveCche application tables,
      and the table /SAPAPO/ORDKEY will be listed. >
    dbmcli on LCT> sql_execute select * from tables where owner='SAPLCT'
    dbmcli on LCT> sql_execute select count(*) from "SAPLCT"."/SAPAPO/ORDKEY"
    < to get number of the entries in the table with owner - SAPLCT >
    dbmcli on LCT>exit
    You could also to check what user did you set for the LCA connection.
    And run //om16 transaction in the liveCache relevant client on the system
    to see the entries in the /sapapo/ordkey & /sapapo/ordmap in liveCache in this client.
    Question: What details you need about table /SAPAPO/ORDKEY?
              Do you have problems on your system?
    Thank you and best regards, Natlia Khlopina

  • How to join two tables using UD Connect ?

    Hi,
    I have 2 tables on which I need to create join & extract the data from Oracle database using UD connect. Is this possible? If yes, please let me know how or suggest an alternative approach.
    Thanks,
    Sunil

    Thanks Tony for the reply..  Actually, the issue is Netweaver Java dictionary doesn't allow you to create a view, right? Also, I dont want to create a view directly on the database.
    I want to handle this on BI side somehow.

  • How to  Join two tables using the Inner Join

    Hi All,
    I have two tables i.e table1 and table2 as i have created two otds and my present requirement is to join this two tables and get the results and using this i need to do some logic and update another table3.
    can some one help me out how to go for the above req.
    Thanks in Advance
    Srikanth

    The best efficient way to use inner join is create two input otds,use there otd's in create a collaboration usinf etl.
    after selecting two input otd's create a inner join statement and map it to out put otd.
    while using the etl the performance of the over all integration is increased 20 time of the normal integration.
    Hopes this will helps,,
    Thanks,
    Papa Rao.

  • How to join two tables

    hi
    how to join two tables using inner join  if the first table has two primary keys and second table has 3 primary keys

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

  • How to process each records in the derived table which i created using cte table using sql server

    I want to process each row from the CTE table I created, how can I traverse from first row to second row and so on....
    how to process each records in the derived table which i created using  cte table using sql server

    Ideally you would be doing a set based processing rather than traversing row by row as thats more efficient. To answer it specific to your scenario we may need more info. Can you explain with some sample data your exact requirement?
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to get the complete definition of a table using SQL?

    How to get the complete definition code of a table using SQL?

    Something like this ?
    SQL> set long 10000
    SQL> set pages 200
    SQL> select dbms_metadata.get_ddl('TABLE','EMP') from dual;
    DBMS_METADATA.GET_DDL('TABLE','EMP')
      CREATE TABLE "SCOTT"."EMP"
       (    "EMPNO" NUMBER(4,0),
            "ENAME" VARCHAR2(10),
            "JOB" VARCHAR2(9),
            "MGR" NUMBER(4,0),
            "HIREDATE" DATE,
            "SAL" NUMBER(7,2),
            "COMM" NUMBER(7,2),
            "DEPTNO" NUMBER(2,0),
             CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS"  ENABLE,
             CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
              REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS"
    SQL>Amardeep Sidhu

  • How to find out the script for the table using SQL

    Hi,
    Could any one tell me that how to find out the script for the table using SQL.
    Thanks,
    kamal

    Kamal,
    You can find the SQL query in Advanced tab of Answers
    Thanks,
    Balaa...

  • How do I add more than one column to a table using SQL?

    Hi
    I need to add 3 columns to a table using SQL
    the syntax
    "ALTER TABLE TEST ADD COLUMN newcol1 float";
    works fine - for adding one coumn only.
    For multiple columns I tried various permutations along the lines of
    "ALTER TABLE TEST ADD (COLUMN newcol01 float, COLUMN new2 float,COLUMN new3 float)";
    "ALTER TABLE TIPSTEST ADD COLUMN new1 float"
    "ALTER TABLE TIPSTEST ADD COLUMN new2 float"
    "ALTER TABLE TIPSTEST ADD COLUMN new3 float"
    etc., but this doesn't work.
    From a web search it sounds like SQL can only add one column at a time.
    I have a workaround : create intermediate temporary tables , copying data and adding
    one column at each stage. It seems a fairly awkward way of programming though.
    Am I missing something simple : is there a way to add multiple columns in one go?
    Thanks

    OK : solved an underlying problem with this one myself
    for the code
    String createString;
    createString =  "select COFFEES.* INTO NEWCOFFEES FROM COFFEES"; // example
              Statement stmt;
              try {
                   stmt = a_Globals.database1Connection.createStatement();
                          stmt.executeUpdate(createString);
                   stmt.close();
                   a_Globals.database1Connection.close();
              } catch(SQLException ex) {
                   System.err.println("SQLException: " + ex.getMessage());
              }                    commenting out the line:
    a_Globals.database1Connection.close();
    Allowed the subsequent SQL statement(s) to work OK. Looks like this was the cause of several
    difficulties, preventing me doing several SQL instructions in turn.
    Thanks for the responses.
    Mike2z

  • How to store Multiple Ec\xcels into Table Using sql loder

    Plese guide me to store Multiple Ec\xcels into Table Using sql loder

    I am not clear with your question. Do you want to load multipel Excel Files into a table. If so you can follow this link.
    http://www.orafaq.com/wiki/SQL*Loader_FAQ#Can_one_load_data_from_multiple_files.2F_into_multiple_tables_at_once.3F
    Thanks,
    Karthick.

  • Need help to join two tables using three joins, one of which is a (between) date range.

    I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
    the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
    ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
    [ABCTABLE]
    ABCORDER
    ABCPART
    ABCSERIAL
    ABCDATE
    [ZYXTABLE]
    XYZORDER
    XYZPART
    XYZSERIAL
    XYZDATE1
    XYZDATE2

    Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
    on this computer. There are no "Null" fields in either of the tables. 
    This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
    [MSORDR]
    MSORDER
    MSPART
    MSSERIAL
    MSOPNDATE
    11111111
    4444444
    55555
    2/4/2015
    22222222
    6666666
    11111
    1/6/2015
    33333333
    6666666
    11111
    3/5/2015
    This table has one order for every part number and every serial number.
    [GLORDR]
    GLORDER
    GLPART
    GLSERIAL
    GLSTARTDATE
    GLENDDATE
    ABC11111
    444444
    55555
    1/2/2015
    4/4/2015
    ABC22222
    666666
    11111
    1/5/2015
    4/10/2015
    AAA11111
    555555
    22222
    3/2/2015
    4/10/2015
    Post Query table
    GLORDER
    MSORDER
    GLSTARTDATE
    GLENDDATE
    MSOPNDATE
    ABC11111
    11111111
    1/2/2015
    4/4/2015
    2/4/2015
    ABC22222
    22222222
    1/5/2015
    4/10/2015
    1/6/2015
    ABC22222
    33333333
    1/5/2015
    4/10/2015
    3/5/2015
    This is the SQL minus the between date join.
    SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
    FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART);

  • Join two tables using union

    Hi Gurus,
    I have three tables. I want to join all tables using union in SQL statement. The query is returning all the records from both tables but i only require unique rows based on a specific column value. Here is my table structure -
    TableA -
    LIC_ID          NUMBER(10)     NOT NULL
    LIC_NUMBER     VARCHAR2(20)
    COMMENCE_DATE     DATE
    EXPIRY_DATE     DATE
    TERM          VARCHAR2(20)LIC_ID is the primary key in this table -
    Sample data from TableA
    LIC_ID          LIC_NUMBER     COMMENCE_DATE          EXPIRY_DATE     TERM
    2          TR4323          12/04/2008          11/03/2010     2 Years
    34          TR5432          23/07/2009          22/07/2010     1 Year
    45          TR5321          24/06/2009          23/06/2010     1 Year
    65          TR6666          23/07/2010          22/07/2011     1 Year
    32          TR2423          30/05/2010          29/05/2011     1 YearTableB -
    MAR_ID          NUMBER(10)     NOT NULL
    LIC_ID          NUMBER(10)     NOT NULL
    ZONE_NAME     VARCHAR2(20)
    DEPARTMENT     VARCHAR2(20)
    ACTIVITIES     VARCHAR2(200)
    COMMENTS     VARCHAR2(200)MAR_ID is the primary key in this table and LIC_ID is the foreign key on TableA
    Sample data from TableB -
    MAR_ID          LIC_ID          ZONE_NAME     DEPARTMENT     ACTIVITIES     COMMENTS
    23          2          ZONE A          IT          NONE               
    43          34          ZONE B          IT          NONE
    33          65          ZONE C          ACCOUNT          NONE     
              TableC
    REC_ID          NUMBER(10)     NOT NULL
    LIC_ID          NUMBER(10)     NOT NULL
    DIST_NAME     VARCHAR2(20)
    REGION          VARCHAR2(20)
    ACTIVITIES     VARCHAR2(200)
    COMMENTS     VARCHAR2(200)REC_ID is the primary key in this table and LIC_ID is the foreign key.
    Sample data -
    REC_ID          LIC_ID          DIST_NAME     REGION          ACTIVITIES     COMMENTS
    2          45          SA          NORTH          NONE
    3          65          TA          NORTH          NONE
    5          32          NT          SOUTH          NONEHere is my sql query -
    select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
    TableA a, TableB b
    where a.lic_id=b.lic_id
    union
    select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
    TableA a, TableC c
    where a.lic_id=c.lic_idThe above query returns -
    lic_id          lic_number     commence_date          expiry_date          
    2          TR4323          12/04/2008          11/03/2010     
    34          TR5432          23/07/2009          22/07/2010     
    45          TR5321          24/06/2009          23/06/2010     
    65          TR6666          23/07/2010          22/07/2011     
    32          TR2423          30/05/2010          29/05/2011
    65          TR6666          23/07/2010          22/07/2011     LIC_ID 65 exists in both table TableB and TableC hence it repeats in query but I want to display that only once. How can I do that? I want to return unique record on LIC_NUMBER.
    Hope this make sence.
    Many thanks,
    Tajuddin

    Thanks for all your reply and suggestions. David altering session did not work.
    Sven your idea helped me to figure it out what to do. I found a way around to fix it. Here is my current code -
    select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
    TableA a, TableB b
    where a.lic_id=b.lic_id
    union
    select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
    TableA a, TableC c
    where a.lic_id=c.lic_id and c.lic_id not in ( select lic_id from TableB)This will exclude any LIC_ID exists in TableB.
    Thanks again for your help guys.
    Regards,
    M Tajuddin
    Web: http://tajuddin.whitepagesbd.com
    Blog: http://aspblog.whitepagesbd.com

  • Load XML File into temporary tables using sql loader

    Hi All,
    I have an XML file as below. I need to insert the contents into a temporary staging table using sql loader. Please advice how I need to do that.
    For example Portfolios should go into a seperate table, and all the tags inside it should be populated in the columns of the table.
    Family should go into a seperate table and all the tags inside it should be populated in the columns of the table.
    Similarly offer, Products etc.
    - <ABSProductCatalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    - <ProductSalesHierachy>
    - <Portfolios>
    - <Portfolio productCode="P1">
      <Attribute name="CatalogProductName" value="Access" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
    - <Portfolio productCode="P2">
      <Attribute name="CatalogProductName" value="Data" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
    - <Portfolio productCode="P3">
      <Attribute name="CatalogProductName" value="Voice" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
    - <Portfolio productCode="P4">
      <Attribute name="CatalogProductName" value="Wireless" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
      </Portfolios>
    - <Families>
    - <Family productCode="F1">
      <Attribute name="CatalogProductName" value="Internet Access Services" />
      <Attribute name="Status" value="Active" />
    - <ParentHierarchy>
      <Item productCode="P1" modelType="Portfolio" />
      </ParentHierarchy>
      </Family>
    - <Family productCode="F2">
      <Attribute name="CatalogProductName" value="Local Access Services" />
      <Attribute name="Status" value="Active" />
    - <ParentHierarchy>
      <Item productCode="P2" modelType="Portfolio" />
      </ParentHierarchy>
      </Family>
      </Families>
    - <SubFamilies>
    - <SubFamily productCode="SF1">
      <Attribute name="CatalogProductName" value="Business Internet service" />
      <Attribute name="Status" value="Active" />
    - <ParentHierarchy>
      <Item productCode="F1" modelType="Family" />
      </ParentHierarchy>
      </SubFamily>
      </SubFamilies>
    - <ProductRefs>
    - <ProductRef productCode="WSP1" modelType="Wireline Sales Product">
      <ActiveFlag>Y</ActiveFlag>
    - <ProductHierarchy>
      <SalesHierarchy family="F1" subFamily="SF1" portfolio="P1" primary="Y" />
      <SalesHierarchy family="F2" portfolio="P2" primary="N" />
      <FinancialHierarchy quotaBucket="Voice" strategicProdCategory="Local Voice" />
      </ProductHierarchy>
      </ProductRef>
    - <ProductRef productCode="MSP2" modelType="Handset">
      <ActiveFlag>Y</ActiveFlag>
    - <ProductHierarchy>
      <SalesHierarchy portfolio="P4" primary="Y" />
      </ProductHierarchy>
      </ProductRef>
      </ProductRefs>
      </ProductSalesHierachy>
    - <Offers>
    - <Offer productCode="ABN">
      <OfferName>ABN</OfferName>
      <OfferDescription>ABN Description</OfferDescription>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      </Segments>
      <OfferUpdateDate>2009-11-20</OfferUpdateDate>
      <ActiveFlag>Y</ActiveFlag>
      </Offer>
    - <Offer productCode="OneNet">
      <OfferName>OneNet</OfferName>
      <OfferDescription>OneNet Description</OfferDescription>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      <Segment>PCG2</Segment>
      </Segments>
      <OfferUpdateDate>2009-11-20</OfferUpdateDate>
      <ActiveFlag>Y</ActiveFlag>
      </Offer>
      </Offers>
    - <Products>
    - <Product productCode="WSP1" modelType="Wireline Sales Product">
      <ProductName>AT&T High Speed Internet</ProductName>
      <ProductDescription>High Speed Internet</ProductDescription>
      <LegacyCoProdIndicator>SBC</LegacyCoProdIndicator>
      <RevenueCBLCode>1234B</RevenueCBLCode>
      <VolumeCBLCode>4567A</VolumeCBLCode>
      <SAARTServiceIDCode>S1234</SAARTServiceIDCode>
      <MarginPercentRequired>Y</MarginPercentRequired>
      <PercentIntl>%234</PercentIntl>
      <UOM>Each</UOM>
      <PriceType>OneTime</PriceType>
      <ProductStatus>Active</ProductStatus>
      <Compensable>Y</Compensable>
      <Jurisdiction>Everywhere</Jurisdiction>
      <ActiveFlag>Y</ActiveFlag>
    - <Availabilities>
      <Availability>SE</Availability>
      <Availability>E</Availability>
      </Availabilities>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      </Segments>
      <VDIndicator>Voice</VDIndicator>
      <PSOCCode>PSOC 1</PSOCCode>
      <USBilled>Y</USBilled>
      <MOWBilled>N</MOWBilled>
      <ProductStartDate>2009-11-20</ProductStartDate>
      <ProductUpdateDate>2009-11-20</ProductUpdateDate>
      <ProductEndDate>2010-11-20</ProductEndDate>
    - <AliasNames>
      <AliasName>AT&T HSI</AliasName>
      <AliasName>AT&T Fast Internet</AliasName>
      </AliasNames>
    - <OfferTypes>
      <OfferType productCode="ABN" endDate="2009-11-20" />
      <OfferType productCode="OneNet" />
      </OfferTypes>
    - <DynamicAttributes>
    - <DynamicAttribute dataType="String" defaultValue="2.5 Mbps" name="Speed">
      <AttrValue>1.5 Mbps</AttrValue>
      <AttrValue>2.5 Mbps</AttrValue>
      <AttrValue>3.5 Mbps</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="TransportType">
      <AttrValue>T1</AttrValue>
      </DynamicAttribute>
      </DynamicAttributes>
      </Product>
    - <Product productCode="MSP2" modelType="Handset">
      <ProductName>Blackberry Bold</ProductName>
      <ProductDescription>Blackberry Bold Phone</ProductDescription>
      <LegacyCoProdIndicator />
      <RevenueCBLCode />
      <VolumeCBLCode />
      <SAARTServiceIDCode />
      <MarginPercentRequired />
      <PercentIntl />
      <UOM>Each</UOM>
      <PriceType />
      <ProductStatus>Active</ProductStatus>
      <Compensable />
      <Jurisdiction />
      <ActiveFlag>Y</ActiveFlag>
    - <Availabilities>
      <Availability />
      </Availabilities>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      </Segments>
      <VDIndicator>Voice</VDIndicator>
      <PSOCCode />
      <USBilled />
      <MOWBilled />
      <ProductStartDate>2009-11-20</ProductStartDate>
      <ProductUpdateDate>2009-11-20</ProductUpdateDate>
    - <AliasNames>
      <AliasName />
      </AliasNames>
    - <OfferTypes>
      <OfferType productCode="ABN" />
      </OfferTypes>
    - <DynamicAttributes>
    - <DynamicAttribute dataType="String" name="StlmntContractType">
      <AttrValue />
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="BMG 2 year price">
      <AttrValue>20</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="MSRP">
      <AttrValue>40</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="BMGAvailableType">
      <AttrValue />
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="ProductId">
      <AttrValue>123456</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="modelSource">
      <AttrValue>product</AttrValue>
      </DynamicAttribute>
      </DynamicAttributes>
      </Product>
      </Products>
      <CatalogChanged>Y</CatalogChanged>
      </ABSProductCatalog>

    Two options that come to mind. Others exist.
    #1 - {thread:id=474031}, which is basically storing the XML in an Object Relational structure for parsing
    #2 - Dump the XML into either an XMLType based table or column and use SQL (with XMLTable) to create a view that parses the data. This would be the same as the view shown in the above post.
    Don't use sql*loader to parse the XML. I was trying to find a post from mdrake about that but couldn't. In short, sql*loader was not build as an XML parser so don't try to use it that way.

  • Internal table value checking in custom table using SQL...

    I have a table which has following fields:
    X1 TABLE (ZCONfig custom table)     
    LIFNR  land1                   
    123      br                    
    234      br                     
    456      br                     
    567      Gr
    and
    X2 TABLE: (Internal table)
    LIFNR:
    234
    567
    123
    Now I want to see if all the field values of LIFNR in internal table X2 (X2-LIFNR) are present in X1 or not.
    Raise error if it is not.
    How do I do this using SQL ? I guess I have to use read statement.
    Please help. Points will be awarded.
    Thanks.
    Regards

    Hi Tushar,
    1 Ya u are right , we need to use READ statement.
    2. Populate X1 (all records)
       in an internal table.
    3. Then Loop at X2
       and compare with X1.
      ( u can also keep an extra field in X2
        of type c, so that if a record is found,
       mark it as X )
    4. try this code (just copy paste)
    REPORT abc.
    DATA : BEGIN OF itab OCCURS 0,
           bukrs LIKE t001-bukrs,
           present TYPE c,
           END OF itab.
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    itab-bukrs = '1000'.
    APPEND itab.
    itab-bukrs = 'X000'.
    APPEND itab.
    SELECT * FROM t001 INTO TABLE t001.
    LOOP AT itab.
      READ TABLE t001 with key bukrs = itab-bukrs.
      IF sy-subrc = 0.
        itab-present = 'X'.
        MODIFY itab.
      ENDIF.
    ENDLOOP.
    BREAK-POINT.
    regards,
    amit m.
    Message was edited by: Amit Mittal

Maybe you are looking for

  • XML in ORACLE

    Hi I would like to know how XML works and how to set the http server and other stuff if any body working on this are please give some tips, source code snippets, and sites to get documentation... Thanks in advace null

  • Flat file upload program is not working

    Hi Experts, I am using following code to upload a flat file from my local PC to SAP The code is NOT inserting records in zassum, /bic/pzassum and /bic/tzassum. zassum is SAP BW infoobject. I have run debugger and found that data is getting populated

  • IPad 2 incorrectly opens pdf file as an image, Bug? Fix?

    Long time user, I do indeed know how to open pdf files; my issue is after a recent update mail no longer handles a pdf file correctly, it opens the file as an image, once opened there is no possibility of properly reading the document in pages, iBook

  • Thank you for accepting the OTN Beta License Agreement

    http://www.oracle.com/technetwork/database/express-edition/downloads/index.html Interesting that the production XE license agreement says: "You must accept the OTN License Agreement for Oracle Database Express Edition 11g Release 2 to download this s

  • JMS with JRun

    Hi All, I am trying to run the following servlet working as a Message Sender on JRun 3.0 but getting the following error..... Naming Exception: Failed to communicate with localhost:2323 Code---> properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,