UNION

how to effectively join two queries.
lets say I have
select * from employees , how do i join
select * from departments with union .
Thanks

Its not clear from your post that what exactly you want.
If you want all data from both table, then use outer join like:
SQL> select e.*,d.* from employees e left outer join DEPARTMENTS d on(d.DEPARTMENT_ID=e.DEPARTMENT_ID);
OR
SQL> select e.*,d.* from employees e right outer join DEPARTMENTS d on(d.DEPARTMENT_ID=e.DEPARTMENT_ID);
OR
SQL> select e.*,d.* from employees e full outer join DEPARTMENTS d on(d.DEPARTMENT_ID=e.DEPARTMENT_ID);

Similar Messages

  • Materialized view - REFRESH FAST ON COMMIT - UNION ALL

    In a materialized view which uses REFRESH FAST ON COMMIT to update the data, how many UNION ALL can be used.
    I am asking this question because my materialized view works fine when there are only 2 SELECT statement (1 UNION ALL).
    Thank you.

    In a materialized view which uses REFRESH FAST ON COMMIT to update the data, how many UNION ALL can be used.As far as I remember you can have 64K UNIONized selects.
    I am asking this question because my materialized view works fine when there are only 2 SELECT statement (1 UNION ALL).Post SQL that does not work.

  • OAF Export button fetching data in one column - view object using union all

    Dear All,
    Export button showing data in one column from  view object,
    View object is based on mulitple queries with union all ,
    Please let me know the solution for this issue.
    Thanks
    Maheswara Raju

    Maheswara Raju,
    As per my understanding you are not able to export all the View Attribute using export Button. Only the attribute which is used with the item/region will get exported.
    There are few work around in case if you want to export the column without showing on OAF Page. Let me know.
    Cheers
    Gyan

  • Data Federator:  Unioning Multiple Tables into single view possible?

    Hi,
    I have three different databases with tables containing a portion of the same kind of data and I want to union the three different tables together in Data Federator to present a single logical view that has the complete set of data.  Is this possible in Data Federator?  How would I go about doing that?
    Note: I do not have keys to join the tables together on since it's not simply extending the data in one table with additional data in another table and doing an inner join on a unique key.  Instead, for example, there's a customer table for Finance, a customer table for Operations and a customer table for Sales and they all contain the same columns (with maybe slightly different names) and same type of data.  I want to effectively union Finance, Operations and Sales together in a federated/virtualized view so applications can just query from that view to get all the customers from the three different databases.
    I have been unable to do this so far since Data Federator requires each table in a mapping to have a relationship with the other tables in the mapping.
    Thanks for the help.
    Kerby

    I figured out the original question using one mapping for each table but have a new question now. 
    Is it possible for an application to use the combined view from Data Federator to write back into the databases?
    e.g. have an application use the target table in Data Federator and view the results, and based on that update the data in the underlying database that provides the data for the target table?
    Thanks for the help.
    Kerby

  • Which is faster: 2 selects or 1 union

    Hello,
    I have 2 tables... each with 500,000 records each. Each table
    has about 15 columns. Each has a non unique index, because
    there can be multiple records with the same index.
    I AM USING PL/SQL.
    The union goes something like this:
    SELECT tblA.*, tblB.*
    FROM tblA, tblB,
    WHERE A.ID (+)= B.ID
    UNION
    SELECT tblA.*, tblB.*
    FROM tblA, tblB,
    WHERE B.ID (+)= A.ID
    I want all records and fields from table A that are not in table
    B and vice versa.
    NOW THE QUESTION...
    Is it faster to do this union or just perform 2 select
    statements and use logic to get the results I am looking for.
    thanks for your help or other ideas!
    larry
    null

    Hi Larry
    <<I want all records and fields from table A that are not
    in table B and vice versa.>>
    Try this,
    Select *
    from tbl a
    where not exists (select 'x'
    from tbl b
    where b.id = a.id)
    union
    select *
    from tbl b
    where not exists (select 'x'
    from tbl a
    where a.id = b.id)
    This would be faster.
    -Raj
    larry (guest) wrote:
    : Hello,
    : I have 2 tables... each with 500,000 records each. Each table
    : has about 15 columns. Each has a non unique index, because
    : there can be multiple records with the same index.
    : I AM USING PL/SQL.
    : The union goes something like this:
    : SELECT tblA.*, tblB.*
    : FROM tblA, tblB,
    : WHERE A.ID (+)= B.ID
    : UNION
    : SELECT tblA.*, tblB.*
    : FROM tblA, tblB,
    : WHERE B.ID (+)= A.ID
    : I want all records and fields from table A that are not in
    table
    : B and vice versa.
    : NOW THE QUESTION...
    : Is it faster to do this union or just perform 2 select
    : statements and use logic to get the results I am looking for.
    : thanks for your help or other ideas!
    : larry
    null

  • UNION statement in ABAP SQL

    Hi,
    How to achieve the UNION SQL operation results in ABAP? To be specific, I want to retrieve STCD1 field value from vendor master table (LFA1) for all vendors (LIFNR) that exist in table BSIK or BSAK.
    And I want to achieve the results in single SQL statement. So in essence, the resultant SQL would be something like:
    SELECT STCD1
    INTO TABLE my_internal_table
    FROM LFA1
    WHERE LIFNR IN (SELECT DISTINCT LIFNR
                                                FROM BSIK
                                UNION
                                SELECT DISTINCT LIFNR
                                               FROM BSAK)
    But the UNION is not a valid keyword in ABAP. Any idea how to achieve this?
    Regards,
    Chetan

    hi chetan,
    do you have any where condition to filter the records from bsak and bsik?
    your requirement cannot be realized in a single statement.
    you have to use two separate selects from bsak and bsik, then, collect all the vendors in one internal table and at last you have to use this table to get the vendor info from lfa1.
    regards,
    ravi

  • Union two tables with diffrent count of fields with null and float value

    Hello,
    i want to union two tables, first one with 3 fields and second one with 4 fields (diffrent count of fields).
    I can add null value at end of first select but it does not work with float values in second table. Value form second table is convert to integer.
    For example:
    select null v1 from sessions
    union
    select 0.05 v1 from sessions
    result is set of null and 0 value.
    As workaround i can type:
    select null+0.0 v1 from sessions
    union
    select 0.05 v1 from sessions
    or simple change select's order.
    Is any better/proper way to do this? Can I somehow set float field type in first select?
    Best regards,
    Lukasz.
    WIN XP, MAXDB 7.6.03

    Hi Lukasz,
    in a UNION statement the first statement defines the structure (number, names and types of fields) of the resultset.
    Therefore you have to define a FLOAT field in the first SELECT statement in order to avoid conversion to VARCHAR.
    Be aware that NULL and 0.0 are not the same thus NULL+0.0 does not equal NULL.
    In fact NULL cannot equal to any number or character value at all.
    BTW: you may want to use UNION ALL to avoid the search and removal of duplicates - looks like your datasets won't contain duplicates anyhow...
    Regards,
    Lars

  • Union query optimalization

    Help me please. I have this query with a Union
    select p.cdpwet, p.jaar, p.vnrproc
    from abgrp p,tbsltbetro bbt
    where p.vnrbslt = bbt.vnrbslt
    and bbt.cdsrt like :n_rol
    and bbt.nrbetr in (select i.nrbetr from tuser i
    where i.naam like :n_naam
    and (i.cdsrtrpers like :n_cdsrtrpers
                   or :n_cdsrtrpers is null)
    and :n_nrbetr is null
    and i.indsrtpers = 'R'
    union
    select to_number(:n_nrbetr)
    from dual
    where :n_nrbetr is not null)
    I will the same result but without a Union.
    Regards,
    Patrick

    Hi Patric,
    probably if you dont want to display UNIQUE values and you are sure that both parts of your query will give different o/p and you just want to club them.. Use UNION ALL.. Your performance problem will be solved, especially when the data fetched is large. Union finds the two data sets and try to sort them to display UNIQUE records only where as UNION ALL just merges them so saving time on sorting.
    Hope that this will help you.
    Regards
    Santa

  • Join, union, and order

    I've been looking at some of the other posts on this and have not seen my exact problem (granted, I have not looked at all of the posts, as there are quite a few, so please forgive me if this has been covered before).
    I have two tables, A & B, that I want to join. They have different data. They both contain fields 1 & 2 which I want to sort by. There are records in A that are not in B, and vice versa.
    I've tried all sorts of things. The closest I've come to what I'm looking for looks like this:
    select * from A, B
    where A1 = B1 (+)
    union
    select * from A, B
    where A1 (+) = B1
    order by A2, A1
    This gives me all the records I'm looking for, but not sorted in the right order. The problem is with records that are in B, but not in A. When sorting by A2, A1 the fields for records in B and not in A are null and appear at the end.
    And yes, I've tried using numbers instead of field names in the order by. Didn't work either. I also tried using NVL to tell it to use B2 if A2 is null.
    Right, left, and outer join do not work on the version I'm using.
    Any ideas??

    here is the example
    SQL> desc t
    Name                                      Null?    Type
    COL                                                VARCHAR2(30 CHAR)
    ID                                                 NUMBER
    SQL> desc t_n
    Name                                      Null?    Type
    N                                                  NUMBER(38)
    SQL> select * from t
      2  union
       select * from t_n;
    select * from t
    ERROR at line 1:
    ORA-01789: query block has incorrect number of result columns
    Note: above error coz no of columns are not same
    SQL> ed
    Wrote file afiedt.buf
      1  select col,id from t
      2  union
      3* select n,null id from t_n
    SQL> /
    select col,id from t
    ERROR at line 1:
    ORA-01790: expression must have same datatype as corresponding expression
    NOTE: got above error as the data type of the column are not same
    SQL> ed
    Wrote file afiedt.buf
      1  select col,id from t
      2  union
      3* select null , n from t_n
    SQL> /
    COL                                    ID
    1#@#2#@#3                               1
    4#@#5#@#6                               2
                                            1
                                          123
    SQL> ed
    Wrote file afiedt.buf
      1  select col,id from t
      2  union
      3  select null , n from t_n
      4* order by id
    SQL> /
    COL                                    ID
    1#@#2#@#3                               1
                                            1
    4#@#5#@#6                               2
                                          123

  • Question regarding Joins and Union

    Hi All,
    Here is the question:
    I have two databases, on which I made a UNION to see both item codes and item names. The issue is that on one database I have an item with the same code than the other, but due human error, on the other database, I have the same name but with an "s" or something like that.
    What I need to do is, when I make a query, I want to see all item codes from both tables, but I want to see only the description from the db1.
    How can I do this?
                                  |      db1                  |    db 2
    ---------------------------   |  -------------------------  | ---------------------------   
    itemcode                 |     ART001            |   ART001
    item name               |     Rock                |   Rocks

    Pavan Patil wrote:
    In my select query I am using only one column (which is part of primary) while joining two base tables and one column of foreign key of other table to get data.
    My query here is whether I have to make use of all the columns of the composite primary key and foreign key to get the values and after making use of this whether performance of the query will be improved ? (Presently my qyery is taking 6.24 mins).
    This is not a question of performance but of what result you want. The result of joining on one column is logically quite different to joining on all of them. I strongly suspect that you will need to join on all three key columns to get a useful result - but that depends on what you are trying to achieve.

  • OBIEE 11g Answers with UNIONs impossible to modify

    Hi Guys,
    I'm upgrading from OBIEE 10.1.3.4.1 to OBIEE 11.1.1.5; after the upgrade using the upgrade tools I find out a problem in the upgraded answers that presents UNIONS in the Criteria.
    The upgraded Answers that have UNIONS apparently works great, but if you try to modify them it is almost impossible, if you modify a formula in one of the criteria in union the same change has replicated in all other criteria.
    Did anyone find this problem?
    Any feedback to overcome it without rebuild all the answers from scratch?
    Regards,
    Daniele

    My two cents, and you might not like the answer...but OBIEE is an analysis tool, not an ETL tool. I'd suggest implementing this logic in your DW / mart load. Not that it can't be done in OBIEE...it just probably shouldn't be.
    My two cents!
    Scott

  • Problem with Union and Currval/NextVal

    Hello,
    I think I may have found a bug with 8.1.5 but I am not sure. Here is the SQL I am trying to execute:
    insert into LFI_TEST_OWNER.CURRVAL_TEST_tb
    SELECT lfi_seq_num_sg.currval
    FROM DUAL
    UNION ALL
    SELECT lfi_seq_num_sg.currval
    FROM DUAL
    When I execute this SQL statement the value inserted into the table is NULL. However when I remove the union and one of the queries then it works as expected.
    Any information on if this is being worked on by Oracle or if it has been fixed would be greatly appreciated.
    Thanks
    Jeff M

    Hi Jeff,
    Nice one. I feel it may not be a bug but as NEXTVAL and CURRVAL are pseudo columns they might not be able to get store in the memory to sort the 2 queries.
    Infact, if you use anyother function in the dual select statment it will return only one row despite of the 2 select statments in the SQL statement. I tried like this,
    SQL> select sysdate from dual
    2 union
    3 select sysdate from dual;
    SYSDATE
    19-JUL-01
    I got only one record. Then I tried like this,
    SQL> select s1.nextval from dual
    2 union
    3 select s1.currval from dual;
    NEXTVAL
    I have given NEXTVAL in the first stmt, still it is returning NULL value only. So I feel it might be PSEUDOCOLUMN effect.
    Any guys who knows better answer are appreciable.
    Thanks
    Srinivas

  • Problem with DATATYPES, in a UNION

    Hello,
    I m trying to disply a custom message when no data found using the below structure. Unfortunately I ve got a problem with the datatypes I m trying to union
    I ve tried various datatypes in the 2nd SELECT but the problem remain. Please help.
    SELECT HOSP_NAME "HOSPITAL", DOC_SUR "SURNAME", DOC_NAME "NAME", d.DOC_ID ID, Diagnosis
    FROM HOSPITAL h, DOCTOR d, (SELECT d.DOC_ID, COUNT (d.DIAGN_ID) Diagnosis
    FROM PATIENT_DIAGNOSIS d
    GROUP BY d.DOC_ID)
    WHERE Diagnosis > 1
    UNION ALL
    SELECT TO_CHAR('test'),TO_CHAR('test'),TO_CHAR('test'),TO_CHAR('test'), 0
    FROM DUAL
    WHERE NOT EXISTS (HOSP_NAME "HOSPITAL", DOC_SUR "SURNAME", DOC_NAME "NAME", d.DOC_ID ID, Diagnosis
    FROM ΝΟΣΟΚΟΜΕΙΟ h, ΙΑΤΡΟΣ d, (SELECT d.DOC_ID, COUNT (d.DIAGN_ID) Diagnosis
    FROM PATIENT_DIAGNOSIS d
    GROUP BY d.DOC_ID)
    WHERE Diagnosis > 1);
    ORA-01790: expression must have same datatype as corresponding expression
    01790. 00000 - "expression must have same datatype as corresponding expression"

    HOSP_NAME "HOSPITAL", DOC_SUR "SURNAME", DOC_NAME "NAME", d.DOC_ID ID, DiagnosisWhat is the data type of these columns
    TO_CHAR('test'),TO_CHAR('test'),TO_CHAR('test'),TO_CHAR('test'), 0What are you doing here 'test' is already a character. Why are you using TO_CHAR?

  • Opening And Closing Balance Using Union ALL

    Hi,
    I have two txt files, once contains AccountNo, OpeningBalance, and the other file contains AccountNo, ClosingBalance. I have two varibles PeriodStart = 1 and PeriodEnd=12.
    I am tring to get this output. I have used two flat file source, sort it, merge it and now struck what else should I do. Any Idea?
    OutPut   Required
    AcNo
    Period
    OpenBal
    CloseBal
    1
    1
    100
    Null
    1
    12
    NULL
    800
    2
    1
    500
    NULL
    2
    12
    NULL
    200
    AcNo
    OpeningBal(£)
    1
    100
    2
    500
    AcNo
    ClosingBal(£)
    1
    800
    2
    200
    MH

    You should have two FLAT FILE sources and add a derived column after both to set the period.
    After that you can union (with
    union transformation instead of merge join) the two sources...
    Please mark the post as answered if it answers your question | My SSIS Blog:
    http://microsoft-ssis.blogspot.com |
    Twitter

  • Report navigation not working properly for the union report

    i have a report which is union and i need to navigate to another report(detailed).the filters are not carried out to the detailed report .Please suggest me on how to get the filters ar e correctly applied on detailed report.I have prompted the fileds in the detailed report.

    Hi,
    Please refer to the below thread.
    Re: OBIEE-UNION Request navigate is not working (Parameter value is not passed)
    Hope it helps!
    Thansk

  • Adding new column in an existing report which was build using Union

    While working in OBIEE 11g I encounter an issue.
    My existing report was build using UNION at Criteria Tab in Analysis. Now I have a requirement to add a new column into the same report. For each criteria I have added the new column but when I go back to the "Result Columns". I see a new field added but it is not allowing me to open or edit column properties for that new column & at the same time it is not allowing me to navigate to other tabs like Results, Promts, and Advanced.
    I don’t want to build this report from scratch. Is there any workaround to get it resolved?

    Hi,
    Just check it once the new added column data types are mismatched or not?
    and the new added column should be navigated into excluded section, so u should edit the report and dragged into the table column section.
    Thanks..

Maybe you are looking for

  • Open dialog box prefs for geany and gnumeric

    I did a reinstall so that /usr/ would no longer have its own partition.   Rearranging the partitions was just going to take too long. I use geany and gnumeric.  File -> Open, in either program, brings up the open dialog box.  It is titled Select a fi

  • Best option for setting up wireless network

    I have ordered a new imac to replace the dying family PC. As it stands, I have my current PC connected to a linksys wireless router and have set up a wireless connection. Since the imac has an internal wireless router, Im not sure what the best way t

  • Adobe premiere CC crash on quit

    Each and every single time I quit Premiere Pro CC it crashes. I get the spinning ball or death then I'm asked to send a report to Apple and Adobe.  Have the most recent version of the program, I've cleared all my preferences and caches. What would be

  • Basics olm vs. iLearning, how to start

    Hi, I'm moving to learn R12 suite after working with g10, will apprecaite your recomendations how better do this. I'm bit confused about iLearning vs. OLM, etc.. Thansk for all tips. T

  • Where to Get Hinge Covers - Pavilion G6

    Hi, I have a Pavilion G6, its model number is 1202EA, both hinge covers have snapped and I am trying to find out where to get replacement hinge covers without going to rip off eBay prices.