Query to join 2 tables by interval of value

Hi all
I need your help in creating a query to join 2 tables by interval of values.
The thing i want to d ois like this: i have 2 tables the first one containing list of serial number and the secon is containing interval of serial number (startnumber and end number) and other information like the user creating the serial number.
I want to list all serial numbers from the first table and the user creating each serial number from the second one if the serial number is between each interval of the second table.
here is an example>
SQL> create table test1 (code varchar2(1), serial number);
Table created.
SQL> create table test2 (requester varchar2(10),startno number, endno number);
Table created.
SQL> insert into test1 values('A',1);
1 row created.
SQL> insert into test1 values('B',3);
1 row created.
SQL> insert into test1 values('C',8);
1 row created.
SQL> insert into test1 values('D',12);
1 row created.
SQL> insert into test1 values('E',20);
1 row created.
SQL> commit;
Commit complete.
SQL> insert into test2 values('TATA',1,5);
1 row created.
SQL> insert into test2 values('TOTO',6,10);
1 row created.
SQL> commit;
Commit complete.
The result i want to get are:
TESt1.CODE     TEST2.REQUESTER
A          TATA
B          TATA
C          TOTO
D          null
E          null

Use outer join:
select  code,
        requester
  from  test1,
        test2
  where serial between startno(+) and endno(+)
  order by code
C REQUESTER
A TATA
B TATA
C TOTO
D
E
SQL> SY.

Similar Messages

  • 1.1 query builder join between tables

    In the latest Sql Developer.
    I invoke the query builder and select multiple tables that have foreign keys between them. These foreign key relationships appear in the diagram (good job).
    How do I make those relationship appear in the SQL that query builder returns to the sql worksheet. I shouldn't have to re-specify them on the where/criteria tab.
    It would be nice if these relationships are defaulted in the joining of tables.

    I overlayed the pre-release versionsDo you mean you installed in the same directory?
    Don't do that.
    There's a system directory (sqldeveloper\sqldeveloper\system) which holds settings and everything, which very well might be corrupted to be used for a newer release.
    Try deleting it, it will be regenerated at next startup. Or even better: re-install in another directory all together...
    K.

  • Seibel Query help : -  Joining Order table with Asset or CX_ACTION table.

    Hi Team
    I need help joining the Order table with the Asset table
    or the Order table with CX_ACTION table to
    Can i get reference on this .
    select x.x_msisdn,
    x.x_product_name,
    x.x_action,
    x.x_status_outcome,
    a.recovered_dt,
    x.x_amount,
    x.created,
    x.x_number_retries,
    o.ORDER_NUM "FMW Order No",
    DECODE(FULFLMNT_STATUS_CD , 'Failed','Failed', o.STATUS_CD) "Order Status"
    from
    siebel.cx_action x,
    siebel.s_order o,
    siebel.s_asset a
    where a.row_id = x.x_asset_id
    and x.created > to_date('08/01/2013 08:00:00', 'dd/mm/yyyy hh24:mi:ss')
    and x.created < to_date('09/04/2013 07:50:00', 'dd/mm/yyyy hh24:mi:ss')
    Regards

    I'm not familiar with Seibel or any of these tables but right off the bat I'd suggest you're missing a join predicate to your s_order table. This could give you far more rows than you're expecting.
    Aside from that you haven't told us what problems you are having. An error? Wrong results? Performance?

  • Joining 3 tables based on the Value from 1 Table

    Dear Oracle Guru's
    I have a Table called Resourcemaster , which stores the details of Resources for the project , The Resources can be of 2 types either our own employees as well as Hired Developers from other consultancies. The following is the proposed Resourcemaster table structure
    Resourcemaster
    Project_id
    Resource_ID
    Resource_type (E - Employees /H - Hired)
    Resource_code
    Employeemaster
    Emp_code
    Emp_Name
    Emp_address
    Hiredresourcemaster
    Hired_code
    Hired_Name
    Hired_Address
    I need to query the resourcemaster , my result should be containing Project id, resource id , Resource type, Resource Name and Resource Address. for which the details are in the above 3 tables . How these 3 tables can be joined and the join is based on the condition, if the resource type is E then resource code = Emp_code from employee master or if the resource type is H then resource_code = Hired_code.
    I am not clear how to join them in a single query and i got stuck
    Kindly Clarify me
    With Warm Regards
    ssr

    ssr wrote:
    I have a Table called Resourcemaster , which stores the details of Resources for the project,So this table should really be called PROJECT_RESOURCES :-)
    The Resources can be of 2 types either our own employees as well as Hired Developers from other consultancies. So you have a table called RESOURCES (id [PK], code [UK?], name, address, resource_type [E or H])
    And the PROJECT_RESOURCES table is this: (project_id [FK to PROJECTS], resource_id [FK to RESOURCES])
    And by modelling your data like this, you'll also find that querying because much easier.
    Hope this helps.
    Regards,
    Rob.

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

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

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

  • Querying the schema for table name with column value!

    In my schema i have 500+ tables and other objects.
    i have a column with the name BO_PRODUCT_CODE.
    I wants to know in what tables the value of BO_PRODUCT_CODE='FX03'.
    i have query the user_tab_columns which gives me the result with 90 tables having the column BO_PRODUCT_CODE.
    What is query which will give me the exact number/name of the table whose column value is FX03. ie, BO_PRODUCT_CODE='FX03'.

    Hi you can use this approach:
    BEGIN
    v_str VARCHAR2(250);
    v_count NUMBER :=0;
    DECLARE
    FOR loop_tbl IN ( SELECT DISTINCT table_name FROM USER_TAB_COLUMNS
    WHERE column_name ='BO_PRODUCT_CODE' )
    LOOP
    v_str := 'SELECT COUNT(*) FROM ' || loop_tbl.table_name || ' WHERE BO_PRODUCT_CODE=||'''' ||'FX03' || '''' '
    EXECUTE IMMEDIATE v_str INTO v_count ;
    IF v_count > 0 THEN
    DBMS_OUTPUT.PUT_LINE ('Table Name :'|| loop_tbl.table_name || ' Count :'||v_count);
    END IF;
    v_count :=0;
    END LOOP;
    EXCEPTION
    WHEN others THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END;
    Please remove if any syntax error.
    Regards

  • How do I join two tables in the same database and load the result into a destination table in a SSIS package

    Hi,
    I have a query that joins two tables in the same database, the result needs to be loaded in a destination DB table.  How do I do this in SSIS package?
    thank you !
    Thank You Warmest Fanny Pied

    Please take a look at these links related to your query.
    http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers
    http://stackoverflow.com/questions/7037228/joining-two-tables-together-in-one-database

  • How to join three tables?

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

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

  • How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?

    1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
    When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed  in the stat plan  ?
    2. Does rowsource statistics gives some kind of  understanding of Extended stats ?

    You can get Row Source Statistics only *after* the SQL has been executed.  An Explain Plan midway cannot give you row source statistics.
    To get row source statistics either set STATISTICS_LEVEL='ALL'  in the session that executes theSQL OR use the Hint "gather_plan_statistics"  in the SQL being executed.
    Then use dbms_xplan.display_cursor
    Hemant K Chitale

  • Select query based on joining of tables from different database is taking too long

    Hi Team,
    Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might
    contain close to 1million records.
    Select T1.*
    From DB1.dbo.Table1 T1
    Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3)
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3
    Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9')
    And (T1.flg IS NULL OR T1.flg = 'N')
    And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
    How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
    Thanks,
    Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

    Thanks.
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    This join is not working with spaces if Rtrim is not used.
    Thanks! Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

  • How to build a query to join on two tables without mapping

    I did Automatic mapping by the workbench Directofield mapping with the table and java object.
    Wanted to build a simple join query by joining on the same field on both the tables.Not the sql query through the toplink using expression builder.
    Please help.............
    Spent one full day for this................

    Thanks Don for the reply,sorry to bug you,but i need help.....
    SELECT A.AGNCY_C,
         A.TYPE_C,
         A.RESN_C,
         A.S_TYPE_C,
         A.SUB_ID_C,
         A.RY_C
    FROM RATING A, REF B
    WHERE A.ID_C = B._ID_C
    AND A.ALPHA_C = B.ALPHA_C
    AND A.EFF_D >= B.MATURITY_D
    This is the real query i was talking about.I did mapping automatically through the workbench,generated java classes also throught the workbench.
    Now they don't want to execute the raw sql.They wanted to get all the RATING objects with the where condition.
    So how to build a query by using toplink.
    tried your example
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression creditRating = builder.getTable("RATING").getField("ID_C");
    Expression issue_ref = builder.getTable("REF").getField("ID_C");
    Expression join = creditRating.equal(issue_ref);
    I am getting java.lang.OutOfMemoryError
    error.
    I selected the option generate classes and descriptors
    from the tables (RATING,REF).,so it created the classes and dscriptors automatically.
    In Database script for the table RATING like this
    ALTER TABLE RATING ADD (
    CONSTRAINT RATING_F1 FOREIGN KEY (ID_C, ALPHA_C)
    REFERENCES REF (ID_C,ALPHA_C));
    I think when i generate descriptor automatically it is keeping this association.
    Please help me.........

  • Query joining 3 tables

    I want to join 3 tables emp,dept,job
    emp
    cid pid dno div job open
    1 1     10 A clerk     A
    1 1     10 A manager     A
    1 1     10 B manager     A
    1 1     20 A salesman     A
    1 1     30 C clerk     A
    dept
    cid pid dno div
    1 1     10 A
    1 1     10 B
    1 1     20 A
    1 1     20 B
    1 1     30 C
    jobtab
    job      sal
    clerk          100
    manager          500
    salesman      200
    My required result is :
    Result
    cid pid dno div job     sal
    1 1     10 A clerk 100
    1 1     10 A manager 500
    1 1     10 B manager 500
    1 1     20 A salesman 200
    1 1     20 B
    1 1     30 C
    My query is something like this :
    select cid,pid,dno,div,job,sal
    from emp e, dept d, jobtab j
    where
    (d.dno=e.dno and d.div=e.div)
    and e.cid=d.cid
    and e.pid=d.pid
    and j.job=e.job
    and e.open='A'
    This query is not fully right. I need to use apprpriate join to get the records in dept table even if there is
    no match in emp eg. the 20B and 30C rows.
    Please modify the query to give the right one.

    SQL> with emp as(
      2  select 1 as cid,1 as pid,10 as dno,'A' as div,'clerk' as job,'A' as open from dual
      3  union select 1,1,10,'A','manager','A' from dual
      4  union select 1,1,10,'B','manager','A' from dual
      5  union select 1,1,20,'A','salesman','A' from dual
      6  union select 1,1,30,'C','clerk','A' from dual),
      7  dept as(
      8  select 1 as cid,1 as pid,10 as dno,'A' as div from dual
      9  union select 1,1,10,'B' from dual
    10  union select 1,1,20,'A' from dual
    11  union select 1,1,20,'B' from dual
    12  union select 1,1,30,'C' from dual),
    13  jobtab as(
    14  select 'clerk' as job,100 as sal from dual
    15  union select 'manager',500 from dual
    16  union select 'salesman',200 from dual)
    17  select nvl(a.cid,b.cid),nvl(a.pid,b.pid),nvl(a.dno,b.dno),nvl(a.div,b.div),c.job,c.sal
    18    from emp a full join dept b
    19      on a.cid = b.cid and a.pid =b.pid and a.dno = b.dno and a.div = b.div
    20    Left join jobtab c
    21      on a.job = c.job and (a.dno,a.div) not in((20,'B'),(30,'C'))
    22  order by 5,4;
    NVL(A.CID,B.CID)  NVL(A.PID,B.PID)  NVL(A.DNO,B.DNO)  N  JOB             SAL
                   1                 1                10  A  clerk           100
                   1                 1                10  A  manager         500
                   1                 1                10  B  manager         500
                   1                 1                20  A  salesman        200
                   1                 1                20  B  null      null
                   1                 1                30  C  null      nullMessage was edited by:
    Aketi Jyuuzou

  • Best way to outer join a table that is doing a sub query

    RDBMS : 11.1.0.7.0
    Hello,
    What is the best way to outer join a table that is doing a sub query? This is a common scenario in EBS for the date tracked tables.
    SELECT papf.full_name, fu.description
      FROM fnd_user fu
          ,per_all_people_f papf
    WHERE fu.user_id = 1772
       AND fu.employee_id = papf.person_id(+)
       AND papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
                                          FROM per_all_people_f per1
                                         WHERE per1.person_id = papf.person_id)Output:
    No output produced because the outer join cannot be done on the sub queryIn this case I did a query in the FROM clause. Is this my best option?
    SELECT papf.full_name, fu.description
      FROM fnd_user fu
          ,(SELECT full_name, person_id
              FROM per_all_people_f papf
             WHERE papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
                                                  FROM per_all_people_f per1
                                                 WHERE per1.person_id = papf.person_id)) papf
    WHERE fu.user_id = 1772
       AND fu.employee_id = papf.person_id(+)Output:
    FULL_NAME     DESCRIPTION
    {null}            John DoeThanks,
    --Johnnie                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    BrendanP wrote:
    ... See the adjacent thread for the other with Row_Number().Do you mean {message:id=10564772} ? Which threads are adjacent is always changing. Post a link.
    I think RANK suits the requirements better than ROW_NUMBER:
    WITH    all_matches     AS
         SELECT  papf.full_name
         ,      fu.description
         ,     RANK () OVER ( PARTITION BY  papf.person_id
                               ORDER BY          papf.effective_start_date     DESC
                        )           AS r_num
         FROM             fnd_user             fu
         LEFT OUTER JOIN      per_all_people_f  papf  ON  fu.employee_id  = papf.person_id
         WHERE   fu.user_id  = 1772
    SELECT     full_name
    ,     description
    FROM     all_matches
    WHERE     r_num     = 1
    Johnnie: I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    See the forum FAQ {message:id=9360002}

  • Named query with join tables

    I have two tables
    - Process_Master (EVENT_ID, EVENT_TYP, STATUS)
    - Rel_Event( EVENT_ID, USERID, EVENT_DATE, RMKS)
    They have one-to-one relationship linked by EVENT_ID.
    I would like to create a named query like below joining 2 tables together.
    Do I need to create any class descriptor first and how? I want this query to be available from the ADF data control so I can drag and drop this to my JSP page as a ADF table. I have no problem in working with single table. I have read thru the developer guide and try out many things like multitable info, aggregate mapping and couldn't figure out how this can be done. Please help!!!
    SELECT A.EVENT_ID,B.EVENT_DATE, A.STATUS, B.RMKS
    FROM PROCESS_MASTER A, REL_EVENT B
    WHERE A.EVENT_ID = B.EVENT_ID
    AND A.STATUS = 'P';
    ********/

    I have tried the below but fail to retrieve any rows. Please help!
    Expression aid = new ExpressionBuilder(ProcEventMaster.class).get("event_id");
    Expression bid = new ExpressionBuilder(RelEvent.class).get("event_id");
    ReportQuery reportQuery = new ReportQuery(ProcEventMaster.class,aid.equal(bid));
    reportQuery.addAttribute("a_id", aid);
    reportQuery.addAttribute("b_id", bid);
    reportQuery.addAttribute("eventDate",bid.get("event_date"));
    reportQuery.addAttribute("remarks",bid.get("rmks"));
    reportQuery.setSelectionCriteria(aid.get("status").equal("P"));
    List<RelEvent> results =
    (List<RelEvent>)session.executeQuery(reportQuery);session.release();
    return results;

  • Joining two tables, sql query

    This is a newbie question! I would like to join two tables. Table_1 contains xml stylesheets:
    id stylesheet doc
    1 <xml stylesheet doc A>
    2 <xml stylesheet doc B>
    And Table_2 contains the XML documents that the stylesheets will transform:
    id XML doc
    1 <XML document 1>
    1 <XML document 2>
    1 <XML document 3>
    2 <XML document 4>
    2 <XML document 5>
    I would like <xml stylesheet doc A> to transform only XML doc that have an id of 1, so I tried this sql statement:
    select a.stylesheet_doc ,b.xml_doc from Table_1 a, Table_2 b where a.id=b.id and a.id=1;
    This statement returns the rows I want (stylesheet doc with id equals 1, and xml_doc with id equals 1), but it pairs each xml document with a style sheet.
    stylesheet doc A <XML document 1>
    stylesheet doc A <XML document 2>
    stylesheet doc A <XML document 3>
    My question is, is there a way to have a result that looks like this?
    stylesheet doc A
    <XML document 1>
    <XML document 2>
    <XML document 3>
    That is, is there a way in sql to get rid of duplicate stylesheet doc A?
    I have tried group by and rollup and xmlagg.
    Thank you very, very much for your help.
    Jim

    Hi, Jim,
    Welcome to the forum!
    You just want to display the XML, not actually transform it, right?
    GROUP BY ROLLUP should work, but I find it easier with GROUP BY GROUPING SETS. Here's an example from tables in the scott schema:
    SELECT       CASE
              WHEN  GROUPING (ename) = 1
              THEN  d.dname
           END          AS dname
    ,       e.ename
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    GROUP BY  GROUPING SETS ( (d.dname, e.ename)
                   , (d.dname)
    ORDER BY  d.dname
    ,       ename          NULLS FIRST
    ;Output:
    DNAME          ENAME
    ACCOUNTING
                   CLARK
                   KING
                   MILLER
    RESEARCH
                   ADAMS
                   FORD
                   JONES
                   SCOTT
                   SMITH
    SALES
                   ALLEN
                   BLAKE
                   JAMES
                   MARTIN
                   TURNER
                   WARDYou may have noticed that this site noramlly compresses whitespace.
    Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Problem with Joins

    Hi, I am trying to write a query to join two tables and get the unmatched rows from the table. For ex: Employee Table:          Employee Labs Emp_Id                Emp_L_ID 1                    1 2                    2 3                    5 4       

  • Bapi Function call from Crystal reports 2008. import parameters syntax.

    Dear, I have an issue with calling a function directly from Crystal reports (2008) in the R3 system. (if this belongs in another thread , please add the link if moved !) I try to get data through function "BAPI_CLASS_GET_CLASSIFICATIONS". Till now al

  • Read XML using DB Link

    Gurus, Is it possible to read/write XML using DB Link? If yes please let me know how to achieve this. Thanks in Advance. Venu

  • Receiving error message corrupt file

    When I try to open Itunes on my PC (Vista) receiving an error message that my file is corrupt or needs to be reinstalled. Can get into Itunes on my IPAD.  If I uninstall will I lose my library?  I have not backed it up on naything external.

  • Unable to create application -2147024891

    <p>I am setting up Planning v4.1.1.1 on a windows server 2003machine and get errors when trying to create anapplication in the planning desktop.  Theerror code I get is as follows:</p><p> </p><p>Unable to create application</p><p>Error Number: -21470