Union & Union All

Hi Everyone,
I have a scenario like this
3 source tables need to be populated in one target table. The same scenario can be achieved in Oracle Warehouse Builder(OWB) by using set operator, where we have different options like Union,Unionall..
How can i achieve the same scenario in ODI.
Any one please help me on this.
Regards
Thiyag

Hi Thiyag,
Never mind. I am not that much in to points and all, the thing is i want to make sure, i am not wasting my time here ( seeking for reorganization is a basic human intention right? ). ;)
Well here you go,
Union:
If you have 3 source table create 3 interface ( put that in a package) with same target.
1 and 2 nd Interface : select IKM SQL Control Append and check the DISTINCT options.
3 rd Interface : Select IKM Incremental Update and make UPDATE option to NO, check DISTINCT option too.
Union All:
1 ,2 nd and 3rd Interface : select IKM SQL Control Append and check the DISTINCT options.
Makes sense?
Thanks,
G

Similar Messages

  • Performing UNION/UNION ALL in views

    I have two databases (DB1 AND DB2) in same server. I have to create two views (V1 AND V2) respectively in DB1 and DB2. And I have to make an union/union all operation in these views (V1 and V2). Is this possible.???.
    Or can I create a single view instead of two views in such a way that the single view contains an union/union all operation between the data taken from two DBs (DB1 and DB2).?
    Any ideas or suggestions on these questions. Your help is well appreciated.
    Thanks in advance.

    Or can I create a single view instead of two views in such a way that the single view contains an union/union all operation between the data taken from two DBs (DB1 and DB2).?
    Make sure you do very thorough testing if you plan to use UNION since that requires a sort operation. And that means that the data from one query has to be sent to the other server before it can be sorted.
    So a query issued on DB1 might sent the DB1 data to DB2 and then send the sorted result back to DB1. But the same query issued on DB2 would already have the DB2 data so after the DB1 data is sent to DB2 and sorted the query is done.
    That is, in one case the entire result set may be sent over the network from one server to the other instead of just one table.

  • ODI 10g Union,Union All,Minus

    Hello,
    I have to use union,union all or minus set on ODI 10.But it doesn't have uninon,union all minus data set like in ODİ 11.How can ı use union statement in odi 10 g?For example I have to union 6 table in odi 10g.How it can be ?
    Thnx a kot

    Thx a lot Jerome .it works
    I have one more question:
    This select captured changed datas.I will delete dataas which returns from this select.And then I will insert new datas.
    I added to IKM COntrol append a new step like this:
    delete from <%=odiRef.getTable("L","TARG_NAME","A")%> T WHERE (<%=odiRef.getTargetColList("", "t.[COL_NAME]", ", ", "\n", "UK")%>) in
    SELECT PK_ID
    FROM <%=odiRef.getFrom()%>
    WHERE (1=1)
    <%=snpRef.getJoin()%>
    <%=snpRef.getFilter()%>
    <%=snpRef.getJrnFilter()%>
    <%=snpRef.getGrpBy()%>
    <%=snpRef.getHaving()%>
    /*commit*/
    I selected "UK" from target.
    But I dont know that it works true.I selected PK_ID from source but which PK_ID Will I select?When targets UK is equal to source UK(PK_ID) then these datas will be deleted.Changed datas will be inserted.How can I modify this step?İs there any solution to do this step?Can I get dynamicly PK_ID?
    Could you help me ?
    Best Regards
    Thanks

  • Union of all the selection variables

    Hi All,
    Is there a way to get a Union of all the available values of selection variables in BEx? For example, if I have a selection variable for 0material and 0country, and I put in 1234 and USA as the selection input.  Normally, you would get a report with '1234' AND 'USA'.  For my case, I want to get the report with '1234' OR 'USA'.  Basically, I want  report with both 0Material = '1234' OR with 0Country = 'USA' in one report.  Thanks in advance for your advice.
    VV

    To only list the material for a particular country.....In the first step, we would list the country before the material in the "rows" section.
    In the "Columns" section, it sounds like there is only one key figure column needed with the variable for the "Country", but do NOT restrict by the "Material".  This should work whether you are showing a count of items or $ cost.
    If this is not right... maybe we could see a simple example from you showing 5 total records with what you want to see in the final report for the columns and rows for 3 records you are trying to capture, etc....
    Edited by: Sharon West on Nov 26, 2008 9:41 AM

  • 집합 연산자(UNION, UNION ALL, INTERSECT, MINUS) 사용 예제

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-12
    집합 연산자(UNION, UNION ALL, INTERSECT, MINUS) 사용 예제
    =========================================================
    Purpose
    집합 연산자인 union, union all, intersect, minus 의 사용방법을 알아보자.
    Explanation
    오라클에서 사용할 수 있는 집합 연산자는 union, union all, intersect,
    minus 가 있다.
    아래의 table은 예제에서 사용될 테이블이다.
    SQL> select * from dept_a;
    DEPTNO DNAME LOC
    10 ACCOUNTING NEW YORK
    20 RESEARCH DALLAS
    30 SALES CHICAGO
    40 OPERATIONS BOSTON
    50 RND SEOUL
    SQL> select * from dept_b;
    DEPTNO DNAME LOC
    20 RESEARCH DALLAS
    30 SALES CHICAGO
    60 FNA SEOUL
    1. UNION Operator
    union은 두 테이블의 자료를 하나의 결과로 가져올 때,
    중복된 row가 있을 경우 하나의 row만을 return한다..
    select 문 절에 사용하는 distinct 와 같은 효과로 생각할 수 있다.
    SQL> select deptno, dname from dept_a
    2 union
    3 select deptno, dname from dept_b;
    DEPTNO DNAME
    10 ACCOUNTING
    20 RESEARCH
    30 SALES
    40 OPERATIONS
    50 RND
    60 FNA
    6 rows selected.
    2. UNION ALL Operator
    union all 은 union이 distinct 를 사용할 때와 달리 중복된
    결과를 모두 return한다. 즉, 결과로 나오는 모든 row를 보여주게 된다.
    SQL> select deptno, dname from dept_a
    2 union all
    3 select deptno, dname from dept_b;
    DEPTNO DNAME
    10 ACCOUNTING
    20 RESEARCH
    30 SALES
    40 OPERATIONS
    50 RND
    20 RESEARCH
    30 SALES
    60 FNA
    8 rows selected.
    3. INTERSECT Operator
    intersect 는 두 테이블의 결과중에 겹치는 row만을 return한다.
    즉, 교집합된 결과로 생각할 수 있다.
    SQL> select deptno, dname from dept_a
    2 intersect
    3 select deptno, dname from dept_b;
    DEPTNO DNAME
    20 RESEARCH
    30 SALES
    4. MINUS Operator
    minus operator는 첫번째 테이블에서 두번째 테이블의 데이터를
    제외한 나머지 row만 return한다.
    SQL> select deptno, dname from dept_a
    2 minus
    3 select deptno, dname from dept_b;
    DEPTNO DNAME
    10 ACCOUNTING
    40 OPERATIONS
    50 RND

    Definitely a bug:
    SQL> ALTER SESSION SET NLS_SORT=BINARY_CI
      2  /
    Session altered.
    SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC
      2  /
    Session altered.
    SQL> with utbl as (
      2                select  chr(ascii('A') + level - 1) letter
      3                  from  dual
      4                  connect by level < 27
      5               ),
      6       ltbl as (
      7                select  chr(ascii('a') + level - 1) letter
      8                  from  dual
      9                  connect by level < 27
    10               )
    11   select  letter
    12     from  utbl
    13  minus
    14   select  letter
    15     from  ltbl
    16  /
    L
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    L
    W
    X
    Y
    Z
    26 rows selected.
    SQL> with utbl as (
      2                select  chr(ascii('A') + level - 1) letter
      3                  from  dual
      4                  connect by level < 27
      5               ),
      6       ltbl as (
      7                select  chr(ascii('a') + level - 1) letter
      8                  from  dual
      9                  connect by level < 27
    10               )
    11  select * from (
    12   select  letter
    13     from  utbl
    14  minus
    15   select  letter
    16     from  ltbl
    17  )
    18  /
    no rows selected
    SQL> SY.

  • ODI Knowledge Module for UNION - UNION ALL - INTERSECT Case Study

    All about BI &amp;amp; Data Integration: ODI Knowledge Module for UNION , UNION_ALL, INTERSECT

    Looks like a discussion/post rather than a question. You can uncheck the "Mark this discussion as a question" while creating the post.

  • Poblem with union/union all giving ORA-22950

    I am using a select statement with xmlelement to create an xml file.
    It has bout 5 different unions in it but I only ever bring one row through.
    I do it like this as then i can use this as one cursor in my plsql without having to create lots of cursors when i only need to use one.
    ie.
    SELECT  xmlelement("QUOTATION",xmlagg(xmlelement(Quotation,
                          xmlelement(CUSTOMERNAME, customername),
                          xmlelement(QUOTE,quoteid )))xmlfile
    From cust, quote
    where custid=quotecustid
    and ptype = 'Q'
    UNION
    SELECT  xmlelement("SALES",xmlagg(xmlelement(SALES,
                          xmlelement(CUSTOMERNAME, customername),
                          xmlelement(QUOTE,salesid )))xmlfile
    From cust, sales
    where custid=salescustid
    and ptype = 'S'Then I use a cursor to run it to a ftp file the one record i have selected by passing in ptype as a parameter.
    if i use union i get ORA-22950 - i have seen other people say use UNION all to get round this.
    if i use union all i will get a value for SALES of no rows i.e.
    Any ideas how i can get round this as dont want to keep creating cursors

    Using different cursors is still the best approach IMO.
    All things considered, it should be more efficient than using only an appearing "smarter" one.
    And it doesn't need to be explicit cursors, it could just be SELECT INTOs wrapped in a PL/SQL CASE statement, with the proper exception handler (if necessary).
    Anyway, if you want to stick with the single-cursor method, there are different ways to do it :
    1) Adding a selector column :
    SELECT xmlfile
    FROM (
      SELECT 'Q' as selector
           , xmlelement("QUOTATION",xmlagg(xmlelement(Quotation,
                      xmlelement(CUSTOMERNAME, customername),
                      xmlelement(QUOTE,quoteid )))xmlfile
      From cust, quote
      where custid=quotecustid
      and ptype = :1
      UNION ALL
      SELECT 'S'
           , xmlelement("SALES",xmlagg(xmlelement(SALES,
                      xmlelement(CUSTOMERNAME, customername),
                      xmlelement(QUOTE,salesid )))xmlfile
      From cust, sales
      where custid=salescustid
      and ptype = :1
    WHERE selector = :1
    ;2) Adding a GROUP BY clause, so that XMLAgg doesn't return anything if no rows are selected :
    SELECT xmlelement("QUOTATION",xmlagg(xmlelement(Quotation,
                    xmlelement(CUSTOMERNAME, customername),
                    xmlelement(QUOTE,quoteid )))xmlfile
    From cust, quote
    where custid=quotecustid
    and ptype = :1
    GROUP BY null
    UNION ALL
    SELECT xmlelement("SALES",xmlagg(xmlelement(SALES,
                    xmlelement(CUSTOMERNAME, customername),
                    xmlelement(QUOTE,salesid )))xmlfile
    From cust, sales
    where custid=salescustid
    and ptype = :1
    GROUP BY null
    ;3) Subqueries :
    SELECT case :1
            when 'Q' then ( SELECT ... )
            when 'S' then ( SELECT ... )
          end as xmlfile
    FROM dual
    ;

  • UNION ALL inthe sql stament

    Hola everyboy,
    I want that one user who hasn`t permiss for edit sql, can do a select with UNION ALL when he want.
    Sometimes he want do selects with UNION, only UNION:
    Select adress FROM TABLE WHERE Column='PEPE'
    UNION
    Select adress FROM TABLE2 WHERE Column='PEPE'
    and sometimes he want do selects with UNION ALL:
    Select adress FROM TABLE WHERE Column='PEPE'
    UNION ALL
    Select adress FROM TABLE2 WHERE Column='PEPE'
    I have seen that if I edit the parameter <Parameter Name="UNION">UNION</Parameter>  in sqlsrv.prm in local machine I could use UNION ALL but this is for ALL selects that I do.
    Is there any other way that I can use?
    Thanks!!

    Hello Cesar,
    please post in what product you are working that we can point youi to teh right forum.
    Crystal Reports Designer ? Universe Designer ?
    Thanks
    Falk

  • Need help in restricting a result set from a UNION in MERGE

    Hello,
    Would really appreciate if anybody could help me out with the issue I am facing with the below statements (I am new to Oracle ):
    merge into table_name_1 p
    using
      select p_key, value_1, value_2
      from some_tables
      UNION
      select p_key, value_1, value_2
      from some_tables
      UNION
    )t
    on (p.p_key = t.p_key)
    when matched then
      update table_name_1 with value_1 and value_2
    when not matched then
      insert table_name_1 with p_key, value_1, value_2;
    Now, the union of all those selects gives me distinct values and it works most of the times but when I get values like below, the merge fails:
    p_key-----value_1-----value_2
    100-----25-----50
    100-----NULL-----50
    I browsed the net and understood the reason behind this: the result set becomes ambiguous and merge doesn't know which row to insert first and which one to update.
    Now, my requirement is: I could have any of the below scenario/result sets from the union and I need only 1 row per p_key -
    result_set_1
    p_key-----value_1-----value_2
    100-----25-----50 ***************need this row
    100-----NULL-----50
    100-----NULL-----NULL
    result_set_2
    p_key-----value_1-----value_2
    100-----25-----NULL ***************need this row
    100-----NULL-----NULL
    result_set_3
    p_key-----value_1-----value_2
    100-----25-----NULL ***************need this row (p_key = 100)
    100-----NULL-----NULL
    200-----NULL-----75 ***************need this row (p_key = 200)
    200-----NULL-----NULL
    300-----90-----95 ***************need this row (p_key = 300)
    So, I basically need a way to restrict the values that I will get from the UNION of all those selects to fit the requirement above, hope I was able to explain the issue I am facing.
    Any help would be greatly appreciated.
    Thanks,
    Dpunk

    In all cases the goal is to find an order by value that will make the row you want be first.
    The query I gave is calculating a priority for each row by adding up values showing whether each column is null or not null. The case statements check whether each column is null and need to be added up to give a total priority value.
    Value_1   Value_2   Priority
    Not Null  Not Null  2 + 1 = 3
    Not Null  Null      2 + 0 = 2
    Null      Not Null  0 + 1 = 1
    Null      Null      0 + 0 = 0
    The priority value ends up being a bitmap showing whether each value is null or not null. I think that reflects my mathematics background.
    Another way of getting the same result (suggested to me by your asking why it needs the "+") would be to use two CASE expressions as separate order by items:
    select p_key, value_1, value_2 from
    (select p_key, value_1, value_2, row_number() over
              (partition by p_key
               order by case when value_1 is null then 0 else 1 end DESC,
                        case when value_2 is null then 0 else 1 end DESC
              ) as rn
      from (your UNION query here)
    where rn = 1
    A third way is to use a more complex case statement:
    select p_key, value_1, value_2 from
    (select p_key, value_1, value_2, row_number() over
              (partition by p_key
               order by case when value_1 is NOT null and value_2 is NOT null then 1
                             when value_1 is NOT null and value_2 is     null then 2
                             when value_1 is     null and value_2 is NOT null then 3
                             when value_1 is     null and value_2 is     null then 4
                         end  ASC
              ) as rn
      from (your UNION query here)
    where rn = 1

  • Problems with Union statement

    Hi,
    I'm writing an application with jdbc. I'm using Oracle Release 8.0.5.0.0, j2re 1.4.2_06.
    The query with UNION produces a resultSet with no record while if I execute the same query with Oracle SQL Worksheet I've one record.
    This is the code with a sample query:
    Class.forName(jdbcDriver).newInstance();
    Connection c = DriverManager.getConnection(dbUrl, "**", "**");
    Statement st = c.createStatement();
    String query = "(select fam from people where id=1711) union (select fam from family where fam=397)";
    ResultSet rs = st.executeQuery(query);
    if(rs!=null){
    while(rs.next()){...}
    rs.next is false but I know It's not correct!
    I dont get any exception and until I didn't use the UNION statement all worked fine!
    Please help me, thanks

    ok... I'm replying to myself:
    It works if I write the query as follow:
    "select fam from people where id=1711 union select fam from family where fam=397"
    without '( ... )' !
    bye

  • Sql query to get union of matching rows

    I want to write a sql query that shows union f all the [Type] for each [Key] if [Key] has atleast one [Type] in common and for non matched [Key]s it will return the row as it is.
    For example In the sql table below [Key] '1' and '2' has [Type] 'B' in common and [Key] '1' and '4' has [Type] 'A' in common. In this case [Key] '1', '2' and '4' are related so result will be union of [Type]s in [Key]s '1', '2' and '4' which are 'A', 'B', 'C'
    and 'E' for each [Key]. And [Key] '3' has no [Type] in common so it will return itself.
    Input:
    declare @categories table ([Key] int, [Type] Char(1))
    insert into @categories ([Key], [Type]) values (1, 'A')
    insert into @categories ([Key], [Type]) values (1, 'B')
    insert into @categories ([Key], [Type]) values (2, 'B')
    insert into @categories ([Key], [Type]) values (2, 'C')
    insert into @categories ([Key], [Type]) values (3, 'D')
    insert into @categories ([Key], [Type]) values (4, 'E')
    insert into @categories ([Key], [Type]) values (4, 'A')
    insert into @categories ([Key], [Type]) values (5, 'F')
    insert into @categories ([Key], [Type]) values (5, 'G')
    insert into @categories ([Key], [Type]) values (6, 'G')
    insert into @categories ([Key], [Type]) values (6, 'H')
    Desired output:
    Key Type
    1 A
    1 B
    1 C
    1 E
    2 A
    2 B
    2 C
    3 D
    4 A
    4 B
    4 E
    5 F
    5 G
    5 H
    6 F
    6 G
    6 H

      
    The data element names are wrong. KEY is a reserved word; “Categories" and "type" are called attribute properties in ISO-11179 rules. Matthias Kläy is right; this is a graph problem in disguise, but you can do it with set theory to get  what are called
    equivalence classes. 
    An edge in a graph has two nodes. Some authors allow a single node to count as a edge, but a better way is to put the same node on both ends of the edge. Here is the graph in a table with all the needed constraints. This is why you should post DDL and not be
    so rude.  
    DROP TABLE Graph;
    CREATE TABLE Graph
    (edge INTEGER NOT NULL,
     node_1 CHAR(1) NOT NULL,
     node_2 CHAR(1) NOT NULL,
     CHECK (node_1 <= node_2),
     PRIMARY KEY (node_1, node_2));
    Here is your data in the correct format. 
    INSERT INTO Graph 
    VALUES 
     (1, 'A', 'B'),
     (2, 'B', 'C'),
     (3, 'D', 'D'), -- orphan node
     (4, 'A', 'E'),
     (5, 'F', 'G'),
     (6, 'G', 'H');
    Now Google Warshall's Algorithm. It uses three nested loops and an adjacency array. This is very clean and fast in a procedural language. Not so much in SQL. Let us do this in steps:
    WITH X1 (edge, node1_1, node1_2, node2_1, node2_2 )
    AS
    (SELECT CASE WHEN G1.edge <> G2.edge 
           THEN G1.edge ELSE G2.edge END,
           G1.node_1, G1.node_2, 
           G2.node_1, G2.node_2       
      FROM Graph AS G1, Graph AS G2
     WHERE G1.node_1 IN (G2.node_1, G2.node_2) 
       AND G1.edge <> G2.edge),
    X2 (edge, node_1, node_2)
    AS
    (SELECT edge, 
    CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
    CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
    FROM X1)
    SELECT DISTINCT edge,
           CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
           CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
     FROM X2;
    The X1 subquery gets the paths of length two. The X2 subquery removes the middle node and creates a new sorted edge. Insert these new rows into Graphs, if they are not there. Repeat the process until no more rows are added. 
    DROP TABLE Graph;
    CREATE TABLE Graph
    (edge INTEGER NOT NULL,
     node_1 CHAR(1) NOT NULL,
     node_2 CHAR(1) NOT NULL,
     CHECK (node_1 <= node_2),
     PRIMARY KEY (node_1, node_2));
    INSERT INTO Graph 
    VALUES 
     (1, 'A', 'B'),
     (2, 'B', 'C'),
     (3, 'D', 'D'), -- orphan node
     (4, 'A', 'E'),
     (5, 'F', 'G'),
     (6, 'G', 'H');
    Here is the monster rolled up into a single statement. 
    INSERT INTO Graph
    SELECT DISTINCT edge,
           CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
           CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
     FROM (SELECT edge, 
    CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
    CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
    FROM 
    (SELECT CASE WHEN G1.edge < G2.edge 
           THEN G1.edge ELSE G2.edge END,
           G1.node_1, G1.node_2, 
           G2.node_1, G2.node_2       
      FROM Graph AS G1, Graph AS G2
     WHERE G1.node_1 IN (G2.node_1, G2.node_2) 
       AND G1.edge <> G2.edge) AS X1(edge,node1_1, node1_2, node2_1, node2_2) )
        AS X2(edge, node_1, node_2)
    EXCEPT 
     SELECT * FROM Graph;
     SELECT * FROM Graph ORDER BY edge, node_1, node_2;
    1 A B
    1 A C
    1 B E
    1 C E
    2 B C
    3 D D
    4 A E
    5 F G
    5 F H
    6 G H
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Minimum subset of a set, whose union is same as original set?

    hi,
    if you have a Set of Sets called S, e.g.
    {{1,2},{2,3},{3,4}}
    and want to find the/a minimum subset of S called S', which has the property that
    union(S)==union(S')
    eg
    union({{1,2},{2,3},{3,4}})==union({{1,2},{3,4}})
    where union(S) means the union of all elements of S ie
    union({{1,2},{2,3},{3,4}}) = {1,2,3,4}
    then is there a better way than considering all combinations?
    my first instinct that the largest component set would always be in the result was proved wrong by
    {{1,2,4,5,7,8},{1,2,3,4},{5,6,7,8}}
    I looked on Google, but have not found much - Set Covering sounds like a good name for this but seems related to algebra instead?
    thanks,
    asjf

    We both need to read. S' is a subset of S.
    1. Take the largest set in S, add it to S'.
    2. Take the next largest set in S, call is A. If A
    has any elements that aren't in S', add it to S'
    3. if there are more sets in S, repeat step 2.Oh, I see now. You can stop after all the elements in the union are reprsented in S' though. Also, he has stated that this algorithm produces tha incorrect result for {{1,2,4,5,7,8},{1,2,3,4},{5,6,7,8}}
    i.e. it gives:
    {{1,2,4,5,7,8},{1,2,3,4}}
    when he wants:
    {{1,2,3,4},{5,6,7,8}}
    because they are smaller sets.

  • Alternative for UNION

    Hi
    I have to simple sets of query Q1 and Q2, both of them have the SUM function used, they work just fine separately, but we want the result in 1 single query.
    The problem is that Q1 has a master/detail table relation in the join so whenever we join both queries together the result set is being summed incorrectly according to the number of detail records found in the detail table.
    Of course the solution is to use UNION operator.
    What I'm looking for is an alternative for the UNION
    Are there any analytical functions where I can have the result???
    Query examples:
    TONY@DEV> SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         M.AUXL_CODE,
      3         D.ITEM_CODE,
      4         SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R)) QTY
      5  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      6       ISTD_STOCK_MOUVEMENTS_D D,
      7       IACD_AUXILIARIES X
      8  WHERE M.TMVS_CODE = D.TMVS_CODE
      9    AND M.CPNY_CODE = D.CPNY_CODE
    10    AND M.BRCH_CODE = D.BRCH_CODE
    11    AND M.MVTS_YEAR = D.MVTS_YEAR
    12    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    13    AND X.AUXL_TYPE = M.AUXL_TYPE
    14    AND X.AUXL_CODE = M.AUXL_CODE
    15    AND X.AUXL_RPRSNT_TITLE = 1
    16    AND M.AUXL_TYPE = 1
    17  GROUP BY X.AUXL_RPRSNT_TITLE, M.AUXL_CODE, D.ITEM_CODE;
      GRP_CODE  AUXL_CODE ITEM_CODE                                         QTY
             1      33405 4030010                                           318
             1      33405 4030020                                            22
             1      33405 4030030                                            22
             1      33408 4030010                                            14
             1      33408 4030020                                             2
             1      33408 4030030                                             2
             1      33410 4030010                                           992
             1      33410 4030020                                            42
             1      33410 4030030                                            42
             1      33413 4030010                                           789
             1      33413 4030020                                            38
      GRP_CODE  AUXL_CODE ITEM_CODE                                         QTY
             1      33413 4030030                                            38
             1      33413 5010008                                             1
             1      33413 5010009                                             1
             1      33413 5010012                                             1
    15 rows selected.
    Elapsed: 00:00:00.00
    TONY@DEV> SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         X.AUXL_CODE,
      3         SUM(NVL(A.AGAC_REV_AMT, 0)) AMT,
      4         SUM(NVL(A.AGAC_AMT, 0)) PAID,
      5         SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)) DUE
      6  FROM IACD_PAYM_AGING A,
      7       IACD_AUXILIARIES X
      8  WHERE X.AUXL_TYPE = A.AUXL_TYPE
      9    AND X.AUXL_CODE = A.AUXL_CODE
    10    AND X.AUXL_RPRSNT_TITLE = 1
    11  GROUP BY X.AUXL_RPRSNT_TITLE, X.AUXL_CODE;
      GRP_CODE  AUXL_CODE        AMT       PAID        DUE
             1      33405    845.248      93.34    751.908
             1      33408     37.334      13.34     23.994
             1      33410   2655.328     394.68   2260.648
             1      33413   2103.855    293.302   1810.553
    Elapsed: 00:00:00.00
    TONY@DEV> SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         M.AUXL_CODE,
      3         D.ITEM_CODE,
      4         SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R)) QUANTITY,
      5         NULL AMT,
      6         NULL PAID,
      7         NULL DUE
      8  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      9       ISTD_STOCK_MOUVEMENTS_D D,
    10       IACD_AUXILIARIES X
    11  WHERE M.TMVS_CODE = D.TMVS_CODE
    12    AND M.CPNY_CODE = D.CPNY_CODE
    13    AND M.BRCH_CODE = D.BRCH_CODE
    14    AND M.MVTS_YEAR = D.MVTS_YEAR
    15    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    16    AND X.AUXL_TYPE = M.AUXL_TYPE
    17    AND X.AUXL_CODE = M.AUXL_CODE
    18    AND X.AUXL_RPRSNT_TITLE = 1
    19    AND M.AUXL_TYPE = 1
    20  GROUP BY X.AUXL_RPRSNT_TITLE, M.AUXL_CODE, D.ITEM_CODE
    21  UNION
    22  SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
    23         X.AUXL_CODE,
    24         NULL ITEM_CODE,
    25         NULL QUANTITY,
    26         SUM(NVL(A.AGAC_REV_AMT, 0)) AMT,
    27         SUM(NVL(A.AGAC_AMT, 0)) PAID,
    28         SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)) DUE
    29  FROM IACD_PAYM_AGING A,
    30       IACD_AUXILIARIES X
    31  WHERE X.AUXL_TYPE = A.AUXL_TYPE
    32    AND X.AUXL_CODE = A.AUXL_CODE
    33    AND X.AUXL_RPRSNT_TITLE = 1
    34  GROUP BY X.AUXL_RPRSNT_TITLE, X.AUXL_CODE;
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33405 4030010                                           318
             1      33405 4030020                                            22
             1      33405 4030030                                            22
             1      33405                                                          845.248      93.34    751.908
             1      33408 4030010                                            14
             1      33408 4030020                                             2
             1      33408 4030030                                             2
             1      33408                                                           37.334      13.34     23.994
             1      33410 4030010                                           992
             1      33410 4030020                                            42
             1      33410 4030030                                            42
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33410                                                         2655.328     394.68   2260.648
             1      33413 4030010                                           789
             1      33413 4030020                                            38
             1      33413 4030030                                            38
             1      33413 5010008                                             1
             1      33413 5010009                                             1
             1      33413 5010012                                             1
             1      33413                                                         2103.855    293.302   1810.553
    19 rows selected.
    Elapsed: 00:00:05.03
    TONY@DEV>Here are samples from the joined query
    TONY@DEV> ed
    Wrote file afiedt.buf
      1  SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         M.AUXL_CODE,
      3         D.ITEM_CODE,
      4         SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R)) QUANTITY,
      5         SUM(NVL(A.AGAC_REV_AMT, 0)) AMT,
      6         SUM(NVL(A.AGAC_AMT, 0)) PAID,
      7         SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)) DUE
      8  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      9       ISTD_STOCK_MOUVEMENTS_D D,
    10       IACD_AUXILIARIES X,
    11       IACD_PAYM_AGING A
    12  WHERE M.TMVS_CODE = D.TMVS_CODE
    13    AND M.CPNY_CODE = D.CPNY_CODE
    14    AND M.BRCH_CODE = D.BRCH_CODE
    15    AND M.MVTS_YEAR = D.MVTS_YEAR
    16    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    17    AND X.AUXL_TYPE = M.AUXL_TYPE
    18    AND X.AUXL_CODE = M.AUXL_CODE
    19    AND X.AUXL_TYPE = A.AUXL_TYPE
    20    AND X.AUXL_CODE = A.AUXL_CODE
    21    AND X.AUXL_RPRSNT_TITLE = 1
    22    AND M.AUXL_TYPE = 1
    23* GROUP BY X.AUXL_RPRSNT_TITLE, M.AUXL_CODE, D.ITEM_CODE
    TONY@DEV> /
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33405 4030010                                         10494  30428.928    3360.24  27068.688
             1      33405 4030020                                           726    845.248      93.34    751.908
             1      33405 4030030                                           726    845.248      93.34    751.908
             1      33408 4030010                                           140     373.34      133.4     239.94
             1      33408 4030020                                            20     37.334      13.34     23.994
             1      33408 4030030                                            20     37.334      13.34     23.994
             1      33410 4030010                                         56544 164630.336   24470.16 140160.176
             1      33410 4030020                                          2394  10621.312    1578.72   9042.592
             1      33410 4030030                                          2394   13276.64     1973.4   11303.24
             1      33413 4030010                                         56808  151477.56  21117.744 130359.816
             1      33413 4030020                                          2736  10519.275    1466.51   9052.765
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33413 4030030                                          2736  10519.275    1466.51   9052.765
             1      33413 5010008                                            72   2103.855    293.302   1810.553
             1      33413 5010009                                            72   2103.855    293.302   1810.553
             1      33413 5010012                                            72   2103.855    293.302   1810.553
    15 rows selected.
    Elapsed: 00:00:03.09
    TONY@DEV> ED
    Wrote file afiedt.buf
      1  SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         M.AUXL_CODE,
      3         D.ITEM_CODE,
      4         SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R)) QUANTITY,
      5         SUM(NVL(A.AGAC_REV_AMT, 0)) AMT,
      6         SUM(NVL(A.AGAC_AMT, 0)) PAID,
      7         SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)) DUE
      8  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      9       ISTD_STOCK_MOUVEMENTS_D D,
    10       IACD_AUXILIARIES X,
    11       IACD_PAYM_AGING A
    12  WHERE M.TMVS_CODE = D.TMVS_CODE
    13    AND M.CPNY_CODE = D.CPNY_CODE
    14    AND M.BRCH_CODE = D.BRCH_CODE
    15    AND M.MVTS_YEAR = D.MVTS_YEAR
    16    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    17    AND X.AUXL_TYPE = M.AUXL_TYPE
    18    AND X.AUXL_CODE = M.AUXL_CODE
    19    AND X.AUXL_TYPE = A.AUXL_TYPE
    20    AND X.AUXL_CODE = A.AUXL_CODE
    21    AND A.AUXL_CODE = M.AUXL_CODE
    22    AND A.AUXL_TYPE = M.AUXL_TYPE
    23    AND X.AUXL_RPRSNT_TITLE = 1
    24    AND M.AUXL_TYPE = 1
    25* GROUP BY X.AUXL_RPRSNT_TITLE, M.AUXL_CODE, D.ITEM_CODE
    TONY@DEV> /
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33405 4030010                                         10494  30428.928    3360.24  27068.688
             1      33405 4030020                                           726    845.248      93.34    751.908
             1      33405 4030030                                           726    845.248      93.34    751.908
             1      33408 4030010                                           140     373.34      133.4     239.94
             1      33408 4030020                                            20     37.334      13.34     23.994
             1      33408 4030030                                            20     37.334      13.34     23.994
             1      33410 4030010                                         56544 164630.336   24470.16 140160.176
             1      33410 4030020                                          2394  10621.312    1578.72   9042.592
             1      33410 4030030                                          2394   13276.64     1973.4   11303.24
             1      33413 4030010                                         56808  151477.56  21117.744 130359.816
             1      33413 4030020                                          2736  10519.275    1466.51   9052.765
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33413 4030030                                          2736  10519.275    1466.51   9052.765
             1      33413 5010008                                            72   2103.855    293.302   1810.553
             1      33413 5010009                                            72   2103.855    293.302   1810.553
             1      33413 5010012                                            72   2103.855    293.302   1810.553
    15 rows selected.
    Elapsed: 00:00:00.02
    TONY@DEV>
    Note: If I join the A table with D table the query's returning no rows
    Any suggestions are apreciated
    Tony S. Garabedian

    Hi Laurent,
    I've got the same results as the joined tables without UNION.
    The AUXL_CODE column is detail in the D table and master in M table the query is counting the detail records over and over when joined with table A where the function SUM is executed against columns in this table even with grouping sets
    Am I correct??
    I'm sure there is (must be) another way other than UNION and all the lengthy query but I just can't figure it out.
    samples
      1  SELECT X.AUXL_RPRSNT_TITLE,
      2         X.AUXL_CODE,
      3         D.ITEM_CODE,
      4         DECODE(GROUPING(X.AUXL_CODE), 1, SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R))) QTY,
      5         SUM(NVL(A.AGAC_REV_AMT, 0)) AMT, SUM(NVL(A.AGAC_AMT, 0)) PAID,
      6         SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)) DUE
      7  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      8       ISTD_STOCK_MOUVEMENTS_D D,
      9       IACD_AUXILIARIES X,
    10       IACD_PAYM_AGING A
    11  WHERE M.TMVS_CODE = D.TMVS_CODE
    12    AND M.CPNY_CODE = D.CPNY_CODE
    13    AND M.BRCH_CODE = D.BRCH_CODE
    14    AND M.MVTS_YEAR = D.MVTS_YEAR
    15    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    16    AND X.AUXL_TYPE = M.AUXL_TYPE
    17    AND X.AUXL_CODE = M.AUXL_CODE
    18    AND X.AUXL_TYPE = A.AUXL_TYPE
    19    AND X.AUXL_CODE = A.AUXL_CODE
    20    AND A.AUXL_CODE = M.AUXL_CODE
    21    AND A.AUXL_TYPE = M.AUXL_TYPE
    22    AND X.AUXL_RPRSNT_TITLE = 1
    23    AND M.AUXL_TYPE = 1
    24* GROUP BY GROUPING SETS((X.AUXL_RPRSNT_TITLE), (X.AUXL_RPRSNT_TITLE, X.AUXL_CODE), (X.AUXL_RPRSNT_TITLE, X.AUXL_CODE, D.ITEM_CODE))
    TONY@RIM> /
    AUXL_RPRSNT_TITLE  AUXL_CODE ITEM_CODE                                         QTY        AMT       PAID        DUE
                    1      33405 4030010                                                32162.102    3453.58  28708.522
                    1      33405 4030020                                                  869.246      93.34    775.906
                    1      33405 4030030                                                  869.246      93.34    775.906
                    1      33405                                                        33900.594    3640.26  30260.334
                    1      33408 4030010                                                   373.34      133.4     239.94
                    1      33408 4030020                                                   37.334      13.34     23.994
                    1      33408 4030030                                                   37.334      13.34     23.994
                    1      33408                                                          448.008     160.08    287.928
                    1      33410 4030010                                               171351.747   24864.84 146486.907
                    1      33410 4030020                                                10879.476    1578.72   9300.756
                    1      33410 4030030                                                13599.345     1973.4  11625.945
    AUXL_RPRSNT_TITLE  AUXL_CODE ITEM_CODE                                         QTY        AMT       PAID        DUE
                    1      33410                                                       195830.568   28416.96 167413.608
                    1      33413 4030010                                               157668.977  21411.046 136257.931
                    1      33413 4030020                                                10799.245    1466.51   9332.735
                    1      33413 4030030                                                10799.245    1466.51   9332.735
                    1      33413 5010008                                                 2159.849    293.302   1866.547
                    1      33413 5010009                                                 2159.849    293.302   1866.547
                    1      33413 5010012                                                 2159.849    293.302   1866.547
                    1      33413                                                       185747.014  25223.972 160523.042
                    1                                                           141375 415926.184  57441.272 358484.912
    20 rows selected.
    TONY@RIM> SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         M.AUXL_CODE,
      3         D.ITEM_CODE,
      4         SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R)) QUANTITY,
      5         SUM(NVL(A.AGAC_REV_AMT, 0)) AMT,
      6         SUM(NVL(A.AGAC_AMT, 0)) PAID,
      7         SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)) DUE
      8  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      9       ISTD_STOCK_MOUVEMENTS_D D,
    10       IACD_AUXILIARIES X,
    11       IACD_PAYM_AGING A
    12  WHERE M.TMVS_CODE = D.TMVS_CODE
    13    AND M.CPNY_CODE = D.CPNY_CODE
    14    AND M.BRCH_CODE = D.BRCH_CODE
    15    AND M.MVTS_YEAR = D.MVTS_YEAR
    16    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    17    AND X.AUXL_TYPE = M.AUXL_TYPE
    18    AND X.AUXL_CODE = M.AUXL_CODE
    19    AND X.AUXL_TYPE = A.AUXL_TYPE
    20    AND X.AUXL_CODE = A.AUXL_CODE
    21    AND A.AUXL_CODE = M.AUXL_CODE
    22    AND A.AUXL_TYPE = M.AUXL_TYPE
    23    AND X.AUXL_RPRSNT_TITLE = 1
    24    AND M.AUXL_TYPE = 1
    25  GROUP BY X.AUXL_RPRSNT_TITLE, M.AUXL_CODE, D.ITEM_CODE;
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33405 4030010                                         11118  32162.102    3453.58  28708.522
             1      33405 4030020                                           748    869.246      93.34    775.906
             1      33405 4030030                                           748    869.246      93.34    775.906
             1      33408 4030010                                           140     373.34      133.4     239.94
             1      33408 4030020                                            20     37.334      13.34     23.994
             1      33408 4030030                                            20     37.334      13.34     23.994
             1      33410 4030010                                         58812 171351.747   24864.84 146486.907
             1      33410 4030020                                          2436  10879.476    1578.72   9300.756
             1      33410 4030030                                          2436  13599.345     1973.4  11625.945
             1      33413 4030010                                         59130 157668.977  21411.046 136257.931
             1      33413 4030020                                          2774  10799.245    1466.51   9332.735
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33413 4030030                                          2774  10799.245    1466.51   9332.735
             1      33413 5010008                                            73   2159.849    293.302   1866.547
             1      33413 5010009                                            73   2159.849    293.302   1866.547
             1      33413 5010012                                            73   2159.849    293.302   1866.547
    15 rows selected.
    TONY@RIM>This is with UNION and these are the correct results
    TONY@RIM> ed
    Wrote file afiedt.buf
      1  SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
      2         M.AUXL_CODE,
      3         D.ITEM_CODE,
      4         SUM(DECODE(M.TMVS_OPERATION,6,D.MVTS_QUANTITY_R,11,-D.MVTS_QUANTITY_R)) QUANTITY,
      5         NULL AMT,
      6         NULL PAID,
      7         NULL DUE
      8  FROM ISTD_STOCK_MOUVEMENTS_M M ,
      9       ISTD_STOCK_MOUVEMENTS_D D,
    10       IACD_AUXILIARIES X
    11  WHERE M.TMVS_CODE = D.TMVS_CODE
    12    AND M.CPNY_CODE = D.CPNY_CODE
    13    AND M.BRCH_CODE = D.BRCH_CODE
    14    AND M.MVTS_YEAR = D.MVTS_YEAR
    15    AND M.MVTS_DOC_NUM = D.MVTS_DOC_NUM
    16    AND X.AUXL_TYPE = M.AUXL_TYPE
    17    AND X.AUXL_CODE = M.AUXL_CODE
    18    AND X.AUXL_RPRSNT_TITLE = 1
    19    AND M.AUXL_TYPE = 1
    20  GROUP BY X.AUXL_RPRSNT_TITLE, M.AUXL_CODE, D.ITEM_CODE
    21  UNION
    22  SELECT X.AUXL_RPRSNT_TITLE GRP_CODE,
    23         X.AUXL_CODE,
    24         NULL ITEM_CODE,
    25         NULL QUANTITY,
    26         ROUND(SUM(NVL(A.AGAC_REV_AMT, 0)), 2) AMT,
    27         ROUND(SUM(NVL(A.AGAC_AMT, 0)), 2) PAID,
    28         ROUND(SUM(NVL(A.AGAC_REV_AMT, 0) - NVL(A.AGAC_AMT, 0)), 2) DUE
    29  FROM IACD_PAYM_AGING A,
    30       IACD_AUXILIARIES X
    31  WHERE X.AUXL_TYPE = A.AUXL_TYPE
    32    AND X.AUXL_CODE = A.AUXL_CODE
    33    AND X.AUXL_RPRSNT_TITLE = 1
    34* GROUP BY X.AUXL_RPRSNT_TITLE, X.AUXL_CODE
    TONY@RIM> /
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33405 4030010                                           327
             1      33405 4030020                                            22
             1      33405 4030030                                            22
             1      33405                                                           869.25      93.34     775.91
             1      33408 4030010                                            14
             1      33408 4030020                                             2
             1      33408 4030030                                             2
             1      33408                                                            37.33      13.34      23.99
             1      33410 4030010                                          1014
             1      33410 4030020                                            42
             1      33410 4030030                                            42
      GRP_CODE  AUXL_CODE ITEM_CODE                                    QUANTITY        AMT       PAID     DUE
             1      33410                                                          2719.87     394.68    2325.19
             1      33413 4030010                                           810
             1      33413 4030020                                            38
             1      33413 4030030                                            38
             1      33413 5010008                                             1
             1      33413 5010009                                             1
             1      33413 5010012                                             1
             1      33413                                                          2159.85      293.3    1866.55
    19 rows selected.
    TONY@RIM>Thanks again,
    Tony
    Message was edited by:
    Tony Garabedian

  • Sql query union double rows

    Hi,
    i have a problem with my sql query.
    I need the difference from query 2 - query 1.
    the red marked row should be ignored because its already in table 1.
    Union compares all colums not just the first 3.
    Here's a screen of the problem:
    http://c60.img-up.net/?up=screenoracskt6.JPG
    thx for all

    Hi,
    Welcome to the forum!
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain how you get those results from that data.
    Always say what version of oracle you're using.
    user6754335 wrote:
    Hi,
    i have a problem with my sql query.
    I need the difference from query 2 - query 1.
    the red marked row should be ignored because its already in table 1.
    Union compares all colums not just the first 3.That's right; UNION compare all the columns selected. If you're only interested in 3 of the columns, then only select those 3.
    If you need to display more columns, but not where all 3 of them match, then the best way is probably an outer join; but there are lots of other ways, including NOT EXISTS, NOT IN, and MINUS (in a sub-query).
    Here's a screen of the problem:
    http://c60.img-up.net/?up=screenoracskt6.JPG
    Post anything relevant on this site.

  • UNION on two views in Different databases

    Hi All,
    Could you please help me in sorting out this requirement.
    We have two views in one database and two more views in another database. Now I want to create one view which should give the union of all these four views. We have DB links. Is it possible? If yes please send me the script.
    Thanks in advance to all.
    Thanks & Regards
    Rajesh Amathi

    Hi and welcome to OTN.
    please refer to Oracle books, your question is simple and also a few hard explained.
    You can use union, union all, intersec and of course many join methods. Which one is for you, you should decide it, or let us know what exactly do you need.
    If objects separated different databases, of course db link is necessary.
    example of creation view:
    CREATE VIEW sample_view AS
    SELECT e1.Ename, e2.Empno, e1.Deptno
    FROM table1 t1, table2 t2, table3@remotedb t3, table4@remotedb t4
    WHERE t1.id = t2.id and t3.id=t4.id; --you can join all tables as you want
    to overview of view please refer to : http://www.dba-oracle.com/concepts/views.htm
    Edited by: Ulfet Tanriverdiyev on Aug 3, 2010 2:56 AM

Maybe you are looking for