Merge or Union Multiple Tables to one big table

Hi All,
I am new to SQL and learning great. I have a use to merge multiple tables. Every table has different kind of data but BP ID is same in every table (but some table have more BP IDs and some are less). The below is sample…
Table A
BPID -  Cost – Profit
0001 – 10 -4
0002 -11 - 3
Table B
BPID - Name – Address
0003 – John - Dallas
0002 –Mark - Huston
Table C
BPID – Zip code – State
0004- 74001 – TX
0002-75008 – TX
Output (after merging in Table A+B+C) would be like this…
BPID – Cost – Profit – Name – Address- Zip Code – State
0001 -10-      4      -    NULL      -- NULL – NULL – NULL
0002 – 11 – 3      -     Mark -   Huston ---75008 – TX
0003 – NULL – NULL – John – Dallas – NULL – NULL
0004 – NULL – NULL – NULL – NULL – 75008 – TX
Thanks for your help in this.

I am including you a full example:
create table TableA (BPID VARCHAR(4), Cost INT, Profit INT)
create table TableB (BPID VARCHAR(4), Name VARCHAR(MAX), Address VARCHAR(MAX))
create table TableC (BPID VARCHAR(4), ZipCode VARCHAR(5), State VARCHAR(2))
INSERT INTO TableA VALUES('0001',10,4),('0002',11,3)
INSERT INTO TableB VALUES('0003','John','Dallas'),('0002','Mark','Huston')
INSERT INTO TableC VALUES('0004','74001','TX'),('0002','75008','TX')
SELECT ISNULL(ISNULL(TableA.BPID, TableB.BPID), TableC.BPID) AS BPID,
TableA.Cost, TableA.Profit, TableB.Name, TableB.Address, TableC.ZipCode, TableC.State FROM TableA
FULL OUTER JOIN TableB ON (TableA.BPID = TableB.BPID)
FULL OUTER JOIN TableC ON (TableB.BPID = TableC.BPID)
And the results:

Similar Messages

  • Multiple 'logical joins' between a fact table and one dimension table

    It appears that one cannot create multiple ‘logical joins’ between a fact table and one dimension table in OBIEE using the Oracle BI Administration Tool. For example, considering a Business Model with a dimension table TIMES and a fact table FACT containing START_TIME and END_TIME, we would like to create separate logical joins from FACT to TIMES for the START_TIMEs and END_TIMEs? Obviously, the underlying foreign keys can be created, but as far as I can tell the Oracle BI Administration Tool doesn’t support this. The workaround would be to replicate the TIMES table, but that’s ugly.
    I seek an alternative approach.

    Try this. Create an two aliases for the TIMES dimension (Start & End) in the Physical Layer and then remove foreign key to the "Parent" Times dimension. Create the Foreign Key in the Physical Layer to the new aliases and then create the complex joins in the BMM Layer to the new aliases as well. This will allow you to present both dates within the same table in the Presentation Layer. Not the most elegant solution but it works.

  • Hello! Can't open an IDML file. ID file was created in CC (10). It is a 100 page (50 spreads) doc that is one big table. It was created in CC (10) and saved as an IDML file. I have CS6 and when I try to open it, it shuts down ID almost instantly. The file

    Hello! Can't open an IDML file. ID file was created in CC (10). It is a 100 page (50 spreads) doc that is one big table. It was created in CC (10) and saved as an IDML file. I have CS6 and when I try to open it, it shuts down ID almost instantly. The file was created on a MAC and I am trying to open it on a MAC. Any/all advice is greatly appreciated as I am up against a deadline with this unopened file! Many thanks in advance, Diane

    There's a good chance the file is corrupt. As whomever sent it to you to verify it opens on their end.

  • How can i add two table into one internal table

    I WANT TO ADD THIS TWO DIFFERENT TABLE INTO ONE INTERNAL TABLE PLEASE HELP.
    TABLES: J_1IEXCHDR, J_1IEXCDTL.
    SELECT * FROM J_1IEXCHDR WHERE STATUS = 'P'.
    WRITE: / J_1IEXCHDR-LIFNR,
              J_1IEXCHDR-DOCNO,
              J_1IEXCHDR-EXYEAR,
              J_1IEXCHDR-BUDAT.
    SELECT * FROM J_1IEXCDTL WHERE TRNTYP = J_1IEXCHDR-TRNTYP
                              AND DOCYR  = J_1IEXCHDR-DOCYR
                              AND DOCNO  = J_1IEXCHDR-DOCNO.
       WRITE: / J_1IEXCDTL-EXBAS,
                J_1IEXCDTL-EXBED,
                J_1IEXCDTL-RDOC1,
                J_1IEXCDTL-ECS.
    ENDSELECT.
    ENDSELECT.
    THANKS IN ADVANCED.

    U have to link these 2 tables like this
    <b>SELECT
    J_1IEXCHDR~DOCNO
    FROM J_1IEXCHDR inner join J_1IEXCDTL
    on J_1IEXCHDRDOCYR  = J_1IEXCDTLDOCYR
    WHERE STATUS = 'P'.</b>
    this is sample code only, and u have to check the F.key relationship.
    Regards
    Prabhu

  • SELECT query performance : One big table Vs many small tables

    Hello,
    We are using BDB 11g with SQLITE support. I have a query about 'select' query performance when we have one huge table vs. multiple small tables.
    Basically in our application, we need to run select query multiple times and today we have one huge table. Do you guys think breaking them into
    multiple small tables will help ?
    For test purposes we tried creating multiple tables but performance of 'select' query was more or less same. Would that be because all tables will map to only one database in backed with key/value pair and when we run lookup (select query) on small table or big table it wont make difference ?
    Thanks.

    Hello,
    There is some information on this topic in the FAQ at:
    http://www.oracle.com/technology/products/berkeley-db/faq/db_faq.html#9-63
    If this does not address your question, please just let me know.
    Thanks,
    Sandra

  • Selecting from multiple tables, into one internal table

    Hi,
    What is the best & most efficient method of selecting from multiple table (in my case 6,) into one internal table?
    Thanks,
    John
    Points will be rewarded and all responses will be highly appreciated.

    I have simple example :
    First one - Join 5 tables
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 4 or 5 tables join.
    get run time field f2.
    f3 = f2 - f1 ( Total time).
    Second one - joins 3 table and use for all entries
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 3 tables join and use for all entries
    get run time field f2.
    f3 = f2 - f1. ( Total time )
    Finally you can have time diffrence between the both sql statement.

  • Left Outer Joining multiple tables to one source table FAILS with VLD-1511

    Hi all,
    Is it me, or is OWB unable to handle left outer joining 1 source table to multiple other tables?
    I want to load a fact table so I have 1 source table with measures. This table must be outer joined to some dimensions that have their FK in the fact table.
    The SQL statement would look like this (and is perfectly valid):
    select ...
    from input, dim1, dim2
    where input.c1 = dim1.c1(+)
    and input.c2 = dim2.c2(+);
    I put the where clause in the joiner operator and validate, but that gives me message VLD-1511: A table may be outer joined to at most one other table.
    Even splitting this up into one outer join per joiner still gives this message.
    A search and look around on the forum and on metalink shows there are related issues (like bug 3334035). Seemingly creating a view is the work-around to use.....? (ie downgrading owb to a simple gui tool) }-;
    Have other people experienced this problem of not being able to outer join one input table to multiple other tables?
    Thanks,
    Ed

    I have had some feedback from Oracle. It turns out this has to do with 2 issues. Below I have pasted the text that Support gave me:
    <---------- START QUOTE ---------->
    RESEARCH
    =========
    Bug 3437036 KEY LOOKUP DOES NOT DETECT ORA-1417 IN VALIDATE/GENERATE STEP
    Unpublished Bug 4211684 FORWARD PORT OF BUG 3437036
    shows:
    Some more development has been completed when this bug is fixed in Paris.
    The following are the details:
    1. If the join condition contains a full outer join such as
    tab1.c (+) = tab2.c (+) and tab2.c (+) = tab3.c
    then the new validations implemented for this bug do not apply since
    in OWB, full outer join triggers generation of joins in ANSI syntax.
    ANSI syntax does not have the original problem the base bug of this
    bug reported.
    2. If the join condition does not contain any full outer join condition,
    then the join is generated in Oracle join syntax, which is subject two
    several restrictions. The fix to this bug check two of the restrictions.
    3. The first restriction in Oracle syntax is that the outer join operator
    "(+)" can only directly be attached to a column name. If you attach it
    to an expression, such as the following:
    (tab1.c + 1) (+) = tab2.c
    Then there will be an ORA-936 error at the time of mapping deployment.
    For this case, I have added a validation message VLD-1512 to error out
    this situation.
    4. The second restriction in Oracle syntax is that a table can only be
    outer joined to exactly one other table.
    For example, this is an invalid join in Oracle syntax:
    tab1.c (+) = tab2.c and tab1.d (+) = tab3.d
    because tab1 is left outer joined to tab2 and tab3.
    But note that the following is still valid in Oracle syntax:
    tab1.c (+) = tab2.c and tab1.d = tab3.d (+)
    because tab1 is left outer joined to tab2 and right outer joined to tab3.
    So this latter case does not violate the restriction that "same oj" to
    more than 1 table is not allowed.
    If same oj to more than 1 table is specified in a join condition,
    VLD-1511 will be issued, and the map is made invalid.
    <---------- END QUOTE ---------->
    OWB does a partial validation, ie not all access paths are (can be) checked. A full check is only done by the database itself. So some scenarios (like checking whether multiple tables are outer joined the correct way) are not checked, and in this case are flagged with an error (even though it is actually a correct scenario).
    Seemingly this was not flagged with an error in earlier versions of OWB, so beware, OWB behaviour may change when upgrading...
    Alternative solutions are (1) using key lookups, (2) using a view with all outer joins in there, (3) using intermediate result tables between the joins.
    Hope this info helps some people prevent spending too much time on a false error message,
    Ed

  • How to configure GG to merge two source tables into one destination table?

    I have two tables at source (say S1 & S2), I want to merge these tables and replicate to a single target table (Say T1).
    Does GG support this type of replication? If so, could any one let me know how to configure Table and Map parameters?
    Thanks in advance.

    It is possible. In the extract capture both the tables.
    Extract parameter
    table s1;
    table s2;
    Replicat parameter
    map s1, target t1, keycols (...);
    map s2, target t1, keycols (...)

  • Combining multiple HDs into one big 'un

    So I see where one can make multiple libraries and one can have multiple devices, multiple accounts etc etc... but here's my question. I have an external HD that is holding all my media and is running out of room... Is it possible to "daisy chain" some drives together (i.e. LaCie d2 Quadras, both at 320 GB) and have iTunes read this as one 640 GB drive? In essence so that when I open iTunes and proceed to play content, I don't have to switch out to get it to shuffle music around... I'll prolly end up buying a TB drive but I wanted to ask some of the more enlightened folk on the boards... 'preciate any info!
    Cheers!

    If you go into the iTunes preferences, you can set the location of the iTunes library. What isn't immediately apparent to most people is that this setting only sets the location of FUTURE additions to your library. Anything already in the library will remain where it is and continue to be accessed from that location.
    So to answer your question, you can add an additional drive, point iTunes to a location on the new drive, and everything already in your library will stay on your current external drive. Anything new will be added to the new drive.
    Once you get your BIG drive that can hold everything, you can change the location to that drive. NOW use the consolidate command which will then copy everything NOT in the current iTunes library location to that location. In other words, anything stored outside the currently set iTunes folder location will then be copied in there and the library updated to reflect the new location.
    You can not delete the stuff off the other drives if you wish.
    Cheers,
    Patrick

  • Find duplication values from multiple columns in a big table

    Hi All,
    I am working on a 11gR2 database in linux. i want to display record that have duplicate values in 2 columns.
    1. Table Structure :-
    CREATE TABLE A
    ID NUMBER(10),
    F_NAME VARCHAR2(100 BYTE),
    L_NAME VARCHAR2(100 BYTE)
    2. Sample Data:-
    Insert into A
    (ID, F_NAME, L_NAME) Values (1,'TONY' ,'SUMIT');
    Insert into A
    (ID, F_NAME, L_NAME) Values (2,'SUMIT' ,'KEITH');
    Insert into A
    (ID, F_NAME, L_NAME) Values (3,'NORA','SMITH');
    Insert into A
    (ID, F_NAME, L_NAME) Values (4,'APRIL','TONY');
    Insert into A
    (ID, F_NAME, L_NAME) Values (5,'ROSS','TAM');
    ID F_NAME L_NAME
    1 TONY SUMIT
    2 SUMIT KEITH
    3 NORA SMITH
    4 APRIL TONY
    5 ROSS TAM
    4. My requirement is i need display IDs that it's F_NAME or L_NAME has duplication in F_NAME or L_NAME columns.
    The result should be
    ID
    1 reason: F_NAME (TONY) equals to L_NAME of record 4, L_NAME (SUMIT) equals to F_NAME of record 2
    2 reason: F_NAME (SUMIT) equals to L_NAME of record 1
    4 reason: L_NAME (TONY) equals to F_NAME of record 1
    record 3, 5 aren't in the result because there is no duplication in F_NAME or L_NAME columns for NORA,SMITH, ROSS, TAM
    The table contains 10 million records, i really need to consider the performance.
    kindly suggest me the solution

    Note: Forum members please suggest better approach to this -- below.. convert into SQL :)
    I know I will be opposed by many people in this forum for posting such in-efficient solution.
    But trying to learn along with you.. its an interesting problem which must deal with all rows vs all rows to get all combinations.
    But I am still thinking how to write it in SQL, probably will learn from this post after we receive some good SQL solution for the code what I am currently doing now.
    step 1: created a table B similar to table A and added a column reason
    CREATE TABLE B
      ID      NUMBER(10),
      F_NAME  VARCHAR2(100 BYTE),
      L_NAME  VARCHAR2(100 BYTE),
      REASON  VARCHAR2(1000 BYTE)  --- ADDED THIS
    )Definetely inefficient :(
    BEGIN
       FOR rec_outer IN (SELECT * FROM A) LOOP
          FOR rec_inner IN (SELECT * FROM A) LOOP
             IF (rec_outer.f_name = rec_inner.l_name) THEN
                UPDATE B
                   SET reason =
                             rec_outer.id
                          || ' reason: F_NAME ('
                          || rec_outer.f_name
                          || ') equals to L_NAME of record '
                          || rec_inner.id
                 WHERE b.id = rec_outer.id;
             END IF;
          END LOOP;
          FOR rec_inner IN (SELECT * FROM A) LOOP
             IF (rec_outer.l_name = rec_inner.f_name) THEN
                UPDATE B
                   SET reason =
                          reason
                          || CASE
                                WHEN reason IS NULL THEN
                                   rec_outer.id || ' reason: '
                                ELSE
                             END
                          || 'L_NAME ('
                          || rec_inner.f_name
                          || ') equals to F_NAME of record '
                          || rec_inner.id
                 WHERE b.id = rec_outer.id;
             END IF;
          END LOOP;
       END LOOP;
       COMMIT;
    EXCEPTION
       WHEN OTHERS THEN
          rollback;
          RAISE;
    END;OUTPUT:
    ID     F_NAME     L_NAME     REASON
    1     TONY     SUMIT     1 reason: F_NAME (TONY) equals to L_NAME of record 4,L_NAME (SUMIT) equals to F_NAME of record 2
    2     SUMIT     KEITH     2 reason: F_NAME (SUMIT) equals to L_NAME of record 1
    3     NORA     SMITH     
    4     APRIL     TONY     4 reason: L_NAME (TONY) equals to F_NAME of record 1
    5     ROSS     TAM     Cheers,
    Manik.
    Edited : Added rollback

  • Importing 30 tables into one SQL Table (Help Required)

    Dear Experts,
    I am new in SQL server, actually i need to gather 30 different excel file in one sql server table and i have imported all excel file in different databases, all tables have 186 different columns and datatypes. I couldnt change data type while conversion.
    Now all columns have different data type which are occupying extra space in my database.
    Now the problem is that i need to convert all databases into one database or table. Although i have created a table but i dont have idea how to import all table into one table  and defining datatype in new table while importing the old tables.
    Please help me in this matter or if any body has skype or any other chatting id please do let me know so that i may explain it better.
    Thanking you in advance.
    Best Regards,
    SQL_beginner

    There are several things you can try.  If you have SSIS, take a look at this.
    http://www.singhvikash.in/2013/06/ssis-how-to-load-multiple-excel-files.html
    https://www.simple-talk.com/sql/ssis/importing-excel-data-into-sql-server-via-ssis-questions-you-were-too-shy-to-ask/
    Also, if your files have virtually the same name, like files with dates in the name, you can loop through files in your folder, and increment the loop with each run through.
    DECLARE @intFlag
    INT
    SET @intFlag
    = 1
    WHILE (@intFlag
    <=30)
    BEGIN
    PRINT @intFlag
    declare @fullpath1
    varchar(1000)
    select @fullpath1
    = '''\\path to your files\'
    + convert(varchar,
    getdate()- @intFlag
    , 112)
    + '_your-text-file-name.txt'''
    declare @cmd1
    nvarchar(1000)
    select @cmd1
    = 'bulk insert [dbo].[your-table-name] from '
    + @fullpath1 +
    ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 2, ROWTERMINATOR=''0x0a'')'
    exec (@cmd1)
    SET @intFlag
    = @intFlag + 1
    END
    GO
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • Issue using one 2 Fact tables with one dimension Table.

    Hi,
    I have 1 Dimension table X and 2 Fact tables A and B
    X is joined to Both A and B for Loan Amount ( with A) and for colleatral amount (with B) when I am selecting the X.Product_Name, A.Loan_Amt, B.Collateral Amount, it is giving an error message
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 15018] Incorrectly defined logical table source (for fact table EIP Collateral FACT) does not contain mapping for [EIP Reporting FACT.PD ID]. (HY000)
    Any clues???
    Is there a Inner or Outer join which needs to be created or set in the RPD to get the desired results???

    Ok..
    I have one table which is Porfolio Details which has Portfolio name, Product Category , Product Name, Product ID, Product sources code.- This is my Dimension table.
    I have another 2 set of fact tables : EIP Reporting FACT and EIP Collateral FACT..
    These two tables are joined to Portfolio Details table.
    EIP Reprting FACT gives portfolio wise Loan Amount
    and EIP Collateral FACT gives Portfolio wise Collateral Amount details for same set of customer..
    Now, I am selecting Portfolio Name, Product Category, Product Name,SUM( EIP Reporting FACT.LOAN_AMOUNT), SUM(EIP Collaetral FACT.Collateral_Amt) in a report
    Now, on selecting these columns I am getting that error message which is related to mapping.
    If I take any column from Portfolio details table and any column from EIP Reporting FACT- It works.
    If I take any column from Portfolio details table and any column from EIP Colletral FACT- It works.
    But if I take any column from portfolio table and columns from both FACT tables it gives mapping error...
    Hope I am able to explain the issue in a better way now..
    Edited by: help-required on Mar 11, 2010 6:53 PM
    Edited by: help-required on Mar 11, 2010 6:53 PM

  • Mapping Issue with 7 source tables and one target table in one step

    Hi,
    Request for a small help in OWB.
    I am trying to map 7 source tables to a single target table in one step.These source tables are in Oracle 10G database but dont have PK and FK relation ship.
    I am able to link one table to the target by pointing some of the columns. But when coming to the second table it is giving some error message :
    Ap18003: Connection target attribute group is already connected to a incompatible data source. Use a joiner or set operator to join the upstream data first before connection it to this operator.
    As per the error message I used a Join operator and tried to map the second table to the target but still giving me the same error message. Could some body give me a hand to give out from this step.
    Thanks for your help in advance.
    Cheers,
    Krishna.

    Hi,
    like this:
    Ingroup1
    - id -> Number(9,0)
    - name -> VARCHAR2(500)
    Ingroup2
    - my_id -> Number(9,0)
    - name -> VARCHAR2(500)
    Outgroup
    - id -> point to target_table.id
    - name -> point to target_table.name
    Not:
    Ingroup1
    - id -> Number(9,0)
    - name -> VARCHAR2(500)
    Ingroup2
    - name -> VARCHAR2(500)
    - my_id -> VARCHAR2(9)
    Regards
    Detlef
    null

  • NEED HELP ASAP-populate contents from 5 tables into one master table

    Scenario:
    Assign a new_customer_id to each existing customer of our three business. A master lookup table (M) was given to me with pre-populated (SEQ_NOs), (NEW_CUSTIDs), and NULL in (OLD_CUSTIDS). My duty is to
    (1) Fill the M.OLD_CUSTID column with existing customer ids from T1, T2, T3 (uniquely).
    (2) Once the master lookup table is filled, add (SEQ_NO), and (NEW_CUSTID) column to the 3 existing customer tables to hold the new information.
    (3) At the end of the project, remove the existing customer ids from the T1, T2, T3.
    My problem is that there are no associations between the master table and existing customer tables (no keys). The code would be:
    update M
    set OLD_CUSTID= (select OLD_CUSTID from T1 where M.??=T1.??)
    Since the M.OLD_CUSTID and T1.NEW_CUSTID are NULL at this stage, and there are no keys to tie them together. I don't know how to fill both tables. Can someone help me ASAP? Thanks in Advance.
    -ORACLE Newbi

    I am building a "MASTER LOOKUP TABLE" to map the NEW_CUSTID and the OLD_CUSTID. The columns in this M table are:
    CREATE TABLE MKT.M
         "LOOKUP_SEQ" INTEGER, <=== from sequence
         "NEW_CUSTID" CHAR(6), <=== populated with strings given by biz analyst
         "OLD_CUSTID" INTEGER, <=== need to dump all existing custid (unique)
         PRIMARY KEY ("NEW_CUSTID") RELY NOVALIDATE
         ORGANIZATION INDEX TABLESPACE "MKT"
    Table T1/T2/T3 are slightly different but they all contain:
    CUST_ID INTEGER
    CUST_NAME CHAR(50)
    CUST_SINCE DATE
    CUST_ADDR1 CHAR(30)
    CUST_ADDR2 CHAR(30)
    DITY CHAR(30)
    STATE CHAR(2), etc.
    Since M is the lookup table for old-to-new customer ID mapping. There are no need to associat other than just enter the old IDs into the M table.
    Thanks for helping me. Any suggestion?

  • Multiple Joins from one Dimension Table to single Fact table

    Hi all,
    I have a single fact table with attributes as such:
    Action_ID
    Action_Type
    Date_Started
    Date_Completed
    and a Time Dimension to connect to the fact table. Currently the 2 Date columns in my fact table are in the format of 20090101 (which is the same as my key in the time dimension), if it means anything. I've tried to create multiple joins but have been getting error messages. What is the easiest way to link the time dimension with the two date columns in my fact table? Thanks.

    hi..
    it seems to be, you need to use between operator to join time dimension with fact (i.e. Non-equi join)
    If it's then you should create complex join in physical layer by connecting dimension with your fact.
    select columns and operators in such a way that it resembles something like the below.
    timeDimension.timeKey BETWEEN FactTable.Date_Started AND FactTable.Date_Completed

Maybe you are looking for

  • Not able to login to FWSM via SSH client

    When i am trying to login to FWSM via SSH client and it is throwing an error that "SSH server rejected your password Try again"

  • Xnet problems labview 8.6.1

    Existing Labview code on clients sytems 8.6.1 so have to work with this. Using CAN 2 PCMCIA card for original program development using API Channels was no problem and client ECU could be read without fail over long periods (24 hours plus). PCI card

  • Is anyone having issues with Windows 8 phones not loading mobile versions of websites?

    I was just wondering if anyone with a Windows phone is having problems loading the mobile site version of a Muse site when viewed on the phone? or if there is a known bug or incompatability?

  • ITunes not starting (Win7 64bit) (iTunes 10.3.1 and iTunes 10.6)

    I use to have iTunes 10.3.1, then I uninstalled it and now I tried to get it back but when I installed it again and now it won't open. No error message, NOTHING. I went to TaskManager and iTunes, I will watch under Processes and it will just cut off

  • Maximum size of iTunes library

    Recently purchased WD 3TB External HD for use as iTunes library. Now that my library has reached 2.5TB on the 3TB HD, I receive messages from itunes that there is no more room and cannot add any additional files. Finder still shows 404GB available.