To find common data in 2 columns from two different tables.

Hello

Could someone help me with a querry to discover common data of 2 columns from two different tables?

Thank you
Rajesh

Try as below.

select col1 ,col2 from tab1
intersect
select col1 ,col2 from tab2;

Tags: Database

Similar Questions

  • I want to loop through the data from two different tables using for loop where the query should be replaced at runtime, please help me

    I have the data into two table with the structure of similar column, I want to loop through the data in these two tables

    based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    declare

    l_statement varchar2 (2000);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: =' select * ab ';

    on the other

    l_statement: =' select * from bc';

    end if

    I'm in execute immediate l_statement - something like that, but I don't know

    loop

    dbms_output.put_line (i.a);

    end loop;

    end;

    Something like that, but this isn't a peace of the code work.

    Try this and adapt according to your needs:

    declare

    l_statement varchar2 (2000);

    c SYS_REFCURSOR;

    l_a number;

    l_b varchar2 (20);

    Boolean bool;

    Start

    bool: = true;

    If it is true, then

    l_statement: = "select a, b, AB;

    on the other

    l_statement: = "select a, b from bc;

    end if;

    --

    Open c for l_statement;

    --

    loop

    extract the c in l_a, l_b;

    When the output c % notfound;

    dbms_output.put_line (l_a |') -' || l_b);

    end loop;

    close c;

    end;

    /

  • Select Max (Date) in two different tables...

    Dear all,

    I need the date of last update of two different tables, I mean max (date). We will update one table at a time. Updated once I need to take the last update.

    It can be either in table A table B.

    for example.

    Table A

    Date of the ID

    100 16/05/2014

    101 20/05/2014

    102, 22/05/2014

    Table B

    Date of the ID

    100 04/06/2014

    101, 26/05/2014

    102 21/05/2014

    I need the date of table B (101 26/05/2014) last updated date...

    Hello

    Another way, using much more GRAND:

    SELECT LARGER (max1, max2) x

    FROM (SELECT MAX (mydate) max1

    OF mytable_a

    )

    (SELECT MAX (myotherdate) max2

    OF mytable_b

    )

    ;

    Best regards

    Bruno Vroman.

  • How to find the same column name in different tables in the same schema

    Hello

    I find the 'ename' column name in different tables in the same schema.

    Thank you
    Nr

    Hello

    Try this query

    Select column_name, table_name from user_tab_columns where column_name = 'ENAME ';

    Award points and end the debate, if your question is answered or mark if she was...

    Kind regards

    Lacouture.

  • How can I select the first date (at least) and the corresponding date of two different tables source?

    I have 2 tables, INVOICE and INVOICE_REFNUM similar to below. I'm writing a query that withdrawing the first date (less) for a single record remaining the two tables. Each table records the receipt of invoices, but according to the source of the received invoice some may reside in INVOICE_REFNUM and others the INVOICE table. I also use DECODE on the topic of INVOICE_SOURCE, when the date less is taken from the INVOICE table that contains that field, so if the date is in the field INVOICE_REFNUM DECODE is not necessary. Example:

    INVOICE (table)

    INVOICE_GID INVOICE_SOURCE INSERT_DATE

    ABC. AVRT123 I HAVE 11/03/2012-15:49:32

    ABC. CNWY234 G 12/03/2012 14:07:30

    ABC. UPGF678 M 15/03/2012 20:21:54

    INVOICE_REFNUM (table)

    INVOICE_GID INVOICE_REFNUM_QUAL INVOICE_REFNUM_VALUE INSERT_DATE

    ABC. AVRT123 SOURCE ACS 11/03/2012 14:49:32

    ABC. CNWY234 SOURCE CSA 12/03/2012 13:07:30

    ABC. UPGF678 SOURCE ACS 15/03/2012 21:21:54

    My decode statement is: DECODE ("INVOICE_SOURCE, 'I', 'IDE', 'G', ' Auto-Pay", ', 'Manual')

    If I were to write a query on these two tables, the output will resemble the following:

    INVOICE_GID INVOICE_SOURCE INSERT_DATE

    ABC. AVRT123 ACS 11/03/2012 14:49:32

    ABC. CNWY234 ACS 12/03/2012 13:07:30

    ABC. UPGF678 Manual 15/03/2012 20:21:54

    I worked on it for 2 days, and I was able to pull a date by using the following SQL code, but cannot determine how to extract the corresponding source:

    SELECT THE LEAST (GLOGOWNER. INVOICE_REFNUM. INSERT_DATE, GLOGOWNER. THE INVOICE. INSERT_DATE) AS 'DATE OF THE INVOICE.

    GLOGOWNER. THE INVOICE. INVOICE_GID,

    DECODE (GLOGOWNER. THE INVOICE. INVOICE_SOURCE, 'I', 'IDE', 'G', 'Auto-Pay', ', 'Manual').

    GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_VALUE

    OF GLOGOWNER. INVOICE

    LEFT JOIN GLOGOWNER. INVOICE_REFNUM

    ON GLOGOWNER. THE INVOICE. INVOICE_GID = GLOGOWNER. INVOICE_REFNUM. INVOICE_GID

    WHERE GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_VALUE = "ACS."

    AND GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_QUAL_GID = 'SOURCE '.

    AND GLOGOWNER. THE INVOICE. INVOICE_TYPE = 'I '.

    ORDER OF GLOGOWNER. THE INVOICE. INVOICE_GID

    Any help is greatly appreciated!

    Best regards

    -Adam

    Hello

    Is that what you want?

    SELECT i.invoice_gid

    CASE

    WHEN ir.insert_date<= i.insert_date ="" then ="">

    WHEN i.invoice_souce = 'I' and THEN 'EDI '.

    WHEN i.invoice_souce = 'G' THEN 'debit '.

    WHEN i.invoice_souce = am' THEN 'manual '.

    END AS invoice_source

    , The LEAST (i.insert_date, ir.insert_date) AS insert_date

    I have the Bill OF

    JOIN invoice_refnum ON i.invoice_gid = ir.invoice_gid ir

    WHERE ir.invoice_refnum_value = 'ACS '.

    AND ir.invoice_refnum_qual_gid = 'SOURCE '.

    AND i.invoice_type = 'I '.

    ORDER BY i.invoice_gid

    ;

    There is no reason to do an outer join if you only want the lines with specific values anyway.

    What happens if the 2 tables have exactly the same invoice_date?  The query above takes the invoice_source of invoice_refnum in this case, but that can easily be changed.

    Or the other of the insert_dates can be NULL?

    I hope that answers your question.

    Otherwise, thank you post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also after the results you want from these data (otherwise what you have already posted).

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

  • Reports from two different domains

    Hi all

    Is it possible to account for two different subjects areas, i.e., a report that contains fields from two different areas? If so, how could we select fields from two different disciplines in a single report of responses?

    Thank you!!

    One thing to understand is that if you're imagining having two areas (SAs) poster and then by dragging the columns of each in your application without any preparation, then no, that cannot be done. You would need to make a join in the MDB layer and expose the column of the second subject area in the presentation layer.

    But if you indeed interested in UNION (or cross) queries, then do this:

    Build your first application in the first SA in the usual way. Note the number of columns and the data types of each column.

    Now at the bottom of the workspace of criteria, there is a button called "Combined with application similar." Until it clicks.

    Select your second. You will notice that the contours of the columns in your first query appear. This is to remind you that the number of columns in this second query must be the same as in the first. It also shows the data type of each column for the same reason.

    Once you select your columns and your filters, click result. (Oh, you need to decide what kind of combination you want - click the menu drop down.) The result will be a new application that has data from two SAs in the query and combined in the way you select (union, intersection, etc.)

    This should give you a start.

    They are now, some 'useful' or 'correct' points for users on this thread...

  • How to get into two different tables in two columns of a listbox of multi column

    Hi all

    I have two different tables of the values assume that table 1A (1,2,3,4,5) and another table B (3,4,5,6,7). I want to write these tables in a multicolumn listbox such as 1st column would be A array and 2nd column table B.

    Thnx in advance

    Saki,

    I hope this helps to further

  • Remove the column from the compressed tables

    NLSRTL11.2.0.3.0Production
    Oracle Database 11g Enterprise Edition11.2.0.3.064 bit Production
    PL/SQL11.2.0.3.0Production
    AMT for Linux:11.2.0.3.0Production

    Hello

    I read on how to do to remove a compressed table column - first set unused and then drop unused columns. However, in the example below on the basis of data, I ran it, it does not work. Please, can you tell me WHEN this approach does not work. What is dependent on - settings or something else. Why can't I drop unused columns?

    And the example and errors:

    create table tcompressed compress in select * from all_users;

    > TCOMPRESSED table created.

    ALTER table tcompressed add x number;

    > table TCOMPRESSED altered.

    ALTER table tcompressed drop the x column;

    >

    Error report:

    SQL error: ORA-39726: unsupported operation column add/drag on compressed tables

    39726 00000 - "operation column add/drop not supported on compressed tables. ''

    * Cause: Not support add/column operation move compressed tables

    elapse.

    * Action: When adding a column, do not specify a default value.

    DELETE column is only supported in a column SET UNUSED

    (remove the column metadata).

    ALTER table tcompressed unused column of the set x;

    > table TCOMPRESSED altered.

    ALTER table tcompressed drop unused columns;

    >

    Error report:

    SQL error: ORA-39726: unsupported operation column add/drag on compressed tables

    39726 00000 - "operation column add/drop not supported on compressed tables. ''

    * Cause: Not support add/column operation move compressed tables

    elapse.

    * Action: When adding a column, do not specify a default value.

    DELETE column is only supported in a column SET UNUSED

    (remove the column metadata).

    As you can see even after changing the table defining the column as unused X I still can't drop by DROP UNUSED COLUMNS.

    Thank you.

    If you enable compression for all operations on a table, you can delete the columns in the table. If you enable compression for the only direct-path inserts, you can't remove columns.

  • inserting data in a column in an existing table

    Hi the gems...

    I have an existing table TABLE_1 which has more data in it. This table has no primary key. now, I added a new column 'ID' and want to make it a primary key for this table. currently it is not allowed because the column is null...

    so I need to insert data into the column.
    now, my plan is to fill the column with the data as well as rownumber.

    means that if there are 15 records in this table, then the 'ID' column should contain data from 1 to 15. After that, I'll do the column as a primary key...

    the script I wrote for this:

    declare
    number of v_rownum;

    Start
    Select max (rownum) in the v_rownum from TABLE_1;
    because me in 1.v_rownum
    loop
    Update t set i = t.id TABLE_1 where rownum = i;
    commit;
    end loop;

    end;



    but it refreshes only the first record and the rest of the records are not updated.

    Please help... Thanks in advance...

    Select max (rownum) in the v_rownum from TABLE_1;

    How many rows do you think that this query will retrieve?

    Why not just

    Update TABLE_1 t
    the value t.id = rownum;

  • How to match columns from two tables with

    Hello:
    I have two tables as below:

    Table1::(Base Table)
    Country | Prefix | Prefix_Length
    Travel | 001 | 3
    CountryB. 0012 | 4
    PaysC | 00443 | 5
    CountryD | 0091 | 4

    :(Detail Table) table2
    The population | Area | Prefix
    500 | AreaA | 0015921
    1000 | AreaB | 00122
    400. AreaC. 00443743
    300. ALIS | 0091333
    100. AreaA | 001

    I need to match these two tables with prefix columns (whose length is not fixed in the two tables: but it starts with 00 in the two tables). Two different countries the prefix may be similar up to a certain length. Thus, Prefix_Length can be used to determine (exactly) how much time should be taken in the search of Table2.

    Output:
    Country | Prefix | Area | Population
    Travel | 001 | AreaA | 600
    CountryB. 0012 | AreaB | 1000
    PaysC | 00443 | AreaC. 400
    CountryD | 0091 | ALIS | 300

    Please help me with your valuable comments.

    -Tender

    Try this

    with base_table as (
                        select 'CountryA' country,'001' prefix,3 prefix_length from dual union all
                        select 'CountryB','0012',4 from dual union all
                        select 'CountryC','00443',5 from dual union all
                        select 'CountryD','0091',4 from dual
                       ),
       detail_table as (
                        select 10 no_of_call,'0015921' prefix from dual union all
                        select 3,'00122' from dual union all
                        select 50,'00443743' from dual union all
                      select 50,'00443643' from dual union all
                        select 300,'0091333' from dual union all
                        select 60,'001' from dual
                       ) 
    
    SELECT  country,
            prefix,sum(no_of_call)
       FROM (
             select  country,
            b.prefix,no_of_call,
            decode(no_of_call,lead(no_of_call,1,0) over(partition by no_of_call order by b.prefix,no_of_call),'y','n') y_or_no
      from  base_table b,
            detail_table d
      where b.prefix = substr(d.prefix,1,prefix_length))
      where y_or_no !='y'
      group by  country,
            prefix
      order by country,
            prefix;
    

    Published by: Vi on 20 February 2012 01:07

  • Several lines to a format of columns from two tables

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    The difficulty to return several lines simple lines/columns in two tables.

    Table 1:

    ID BOOK_NBR
    1 1001
    1 2001
    2 1010
    3 1020

    Table 2:

    AUTHOR BOOK_NBR
    1001 JOHN_1
    2001 JOHN_2
    MARY 1010
    1020 JUNE


    Desired output:

    ID BOOK_NBR AUTHOR BOOK_NBR AUTHOR
    1 1001 JOHN_1 2001 JOHN_2
    2 MARY 1010
    3-1020 JUNE


    There are an unknown number of BOOK_NBR to one ID.

    Any guidance would be appreciated.
  • Compare the values of the XMLType column to two different lines using XMLDiff in GR 11, 2

    I have a table of data with a row of XMLType and I need a way to compare the XML data against the other. I guess I could use a function and return a XMLDIFF base output to the caller, but the function logic is a bit fuzzy. Would be nice to format the output finally in a table format.

    I looked on http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions241.htm#SQLRF20025 and output in a format of table as shown in Re: how to find compare and identify between xmldocs .

    I ran across some examples do not explain the best way to compare the XML code that is in the best performing XMLType column.

    Any help would be appreciated.

    Are you referring to different rows in the same table or different tables or?

    Basically, you need to change the example of Odie so that the XMLDiff retrieves the XML from places in Pb, say something like

    XMLDIFF(SELECT aXml FROM table WHERE ...,
            SELECT bXml FROM table WHERE ...)
    

    This allows to avoid bringing the XML of the DB in the client code.

    Don't know if that's what you're looking for, but hopefully it helps a little.

  • How to synchronize files from two different subscriptions in two different Office CC files

    Hello

    I have two subscriptions for CC, work and staff. I ran the subscription of work in two computers at work and at home (when I need to work from home.) The problem I find, is that there are not two different folders to CC for each subscription. When I connect from my subscription to work, all my files from this subscription disappear. Then when I connect again, they all synchronize the process starts again. I chose to have two different subscriptions in order not to mix my personal work of my work. Is it possible to have a CC folder on my desktop for each subscription? In this way, when I log out of an account and switch to the other files of the account that I just connected not replaced for the files in the account in that I just signed.  Help with this will be greatly appreciated.

    Hello

    I just want you know what you should see when using 2 accounts.

    An account:

    1. connect with Adobe ID account

    2. synchronization of files to files creative cloud, which is located in your home directory on Mac or Windows.

    3 newspaper account one, creative Cloud now displays the log in the Panel.

    Two account:

    1. connect with Adobe ID account two

    2. synchronization of files creative Cloud account 2 which is located in your home directory on Mac or Windows. (His Creative Cloud Files account folder is called re)

    Things to check are:

    After you connect to account for two, creative cloud to account 1 file should be renamed, can you check this please make sure there.

    The same is true are you connect again to an account, record of the creative cloud has two will be renamed.

    The data should not have fully re - never synchronize when you open a session on the account 1 and account 2 then, however, can you be sure that the data is actually re download. That is to say; you had 5 GB of data in one account and when you log in account 1 whole 5 GB of data is re download?, could check you this?

    The creative files Cloud Panel will display "Synchronization" for a short time while change you account is, it's normal, and means the application reads data on disc and on the server of checking for changes / added files etc. This isn't re - download all your data, it is simply a check.

    You are able to move the creative cloud files folder to any location on your hard drive via the preferences of creative cloud.

    Thank you

    Warner

  • Amount of effort from 2 different tables

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product


    I have the following tables
    CREATE TABLE  ADDPROJECT
       (     PROJID VARCHAR2(30) NOT NULL ENABLE, 
            PROJNAME VARCHAR2(30) , 
         PROJSTARTDATE DATE, 
            PROJENDDATE DATE,
            PARENTPROJID VARCHAR2(30),
            PROJTYPE VARCHAR2(30),
            PROJSTATUS VARCHAR2(30),
            PRIMARY KEY (PROJID) ENABLE
       )
    
    CREATE TABLE  ADDRESEARCHAREA
       (     RAID VARCHAR2(30) NOT NULL ENABLE, 
            RANAME VARCHAR2(30) , 
         RASTARTDATE DATE, 
            RAENDDATE DATE,
            PARENTRAID VARCHAR2(30),
            RASTATUS VARCHAR2(30),
            PRIMARY KEY (RAID) ENABLE
       )
    
    CREATE TABLE  ALLOCATEASSOCIATES 
       (     PROJID VARCHAR2(30) NOT NULL ENABLE, 
         ASSOCIATEID NUMBER(*,0) NOT NULL ENABLE, 
         ALLOCATIONSTARTDATE DATE, 
            ALLOCATIONPERCENT NUMBER(*,0),
            ENDDATE DATE,
            PRIMARY KEY (PROJID,ASSOCIATEID) ENABLE
       )
    
    CREATE TABLE  PROJECTTORAASSOCIATION
       (     RAID VARCHAR2(30) NOT NULL ENABLE, 
            PROJID VARCHAR2(30) NOT NULL ENABLE, 
         STARTDATE DATE, 
            ENDDATE DATE,
            STATUS VARCHAR2(30),
            PRIMARY KEY (RAID,PROJID) ENABLE
       )
    
    CREATE TABLE  PREVIOUSEFFORT 
       (     PROJID VARCHAR2(30) NOT NULL ENABLE, 
         EFFORTPREVIOUS NUMBER(*,2), 
            PRIMARY KEY (PROJID) ENABLE
       )
    The PreviousEffort effort until March 31, 2012 (in person-months for various projects) and the AllocateAssociates allocation details associated with various projects from April 1, 2012 (effort in person months must be calculated using the date of beginning of allocation and assignment end date).

    Now, I'm writing a report that will add the effort of the two tables and generate a draft report of wise effort (in person-months adding the PreviousEffort and AllocateAssociates tables effort) for a given ResearchArea

    I wrote the below query
    SELECT to_char(SUM(nvl(pe.effortprevious,0)+nvl(EFFORT,0)),999.99 ) AS EFFORT,PROJECTID,PROJECTNAME,RAREAID,RAREANAME
    FROM (
    SELECT
         (SUM
              (MONTHS_BETWEEN(1+nvl(aa.enddate,sysdate),GREATEST(aa.allocationstartdate,to_date('04/01/2012','mm/dd/yyyy')))) 
            ) AS EFFORT,
            aa.projid AS PROJECTID, 
            ap.projname AS PROJECTNAME,
            pr.raID AS RAREAID,
            ar.raName AS RAREANAME
            FROM allocateassociates aa,ProjecttoRAAssociation pr,addProject ap,AddResearchArea ar
            WHERE pr.projid = aa.projid 
            AND aa.projid = ap.projid
            AND pr.raid = ar.raid
            GROUP BY aa.projid,ap.projname,pr.raid,ar.raname
         )
    , previouseffort pe
    WHERE pe.projid = PROJECTID
    GROUP BY PROJECTID,PROJECTNAME,RAREAID,RAREANAME
    1 However, this query works very well if there is an entry for a project in the tables - PreviousEffort and AllocateAssociates. It does not work if there is no entry in one of the tables. For example: a project that started June 1, 2012 will not have an entry in the PreviousEffort table and therefore, get does not appear.

    2. by including the allocationpercent the computation of the effort, I get an error is NOT a GROUP BY
    select (SUM
              (MONTHS_BETWEEN(1+nvl(aa.enddate,sysdate),GREATEST(aa.allocationstartdate,to_date('04/01/2012','mm/dd/yyyy')))) 
               * aa.allocationpercent / 100
            ) AS EFFORT,
    
    ORA-00979: not a GROUP BY expression
    Can you please help to solve the two problems.



    Here are some insert commands.
    insert into addproject values ('proj1','projname1',to_date('04/01/2012','mm/dd/yyyy'),'','','Research Project','Active')
    insert into addproject values ('proj2','projname2',to_date('06/01/2012','mm/dd/yyyy'),'','','Research Project','Active')
    insert into addproject values ('proj3','projname3',to_date('04/01/2012','mm/dd/yyyy'),'','','Research Project','Active')
    
    insert into allocateassociates values ('proj1',1,to_date('04/01/2012','mm/dd/yyyy'),100,'')
    insert into allocateassociates values ('proj1',2,to_date('04/01/2012','mm/dd/yyyy'),100,'')
    insert into allocateassociates values ('proj3',3,to_date('04/01/2012','mm/dd/yyyy'),100,'')
    insert into allocateassociates values ('proj2',4,to_date('06/01/2012','mm/dd/yyyy'),100,'')
    
    insert into addresearcharea values ('ra1','raname1',to_date('04/01/2012','mm/dd/yyyy'),'','','Active')
    insert into addresearcharea values ('ra2','raname2',to_date('04/01/2012','mm/dd/yyyy'),'','','Active')
    
    insert into projecttoraassociation values ('ra1','proj1',to_date('04/01/2012','mm/dd/yyyy'),'','Active')
    insert into projecttoraassociation values ('ra1','proj3',to_date('04/01/2012','mm/dd/yyyy'),'','Active')
    insert into projecttoraassociation values ('ra2','proj2',to_date('04/01/2012','mm/dd/yyyy'),'','Active')
    
    insert into previouseffort values ('proj1',120)
    insert into previouseffort values ('proj3',10.5)

    This?

    SQL> SELECT to_char(SUM(nvl(pe.effortprevious,0)+nvl(EFFORT,0)),999.99 )
      2             AS EFFORT,
      3         PROJECTID,PROJECTNAME,RAREAID,RAREANAME
      4  FROM (
      5  SELECT
    --"Corrected the misplaced paranthesis.."
      6       (SUM
      7        (MONTHS_BETWEEN(
      8                          1+nvl(aa.enddate,sysdate),
      9                                  GREATEST(aa.allocationstartdate,
     10                                     to_date('04/01/2012','mm/dd/yyyy')
     11                                  )
     12                       )
     13             * aa.allocationpercent / 100
     14        )
     15          ) AS EFFORT,
     16          aa.projid AS PROJECTID,
     17          ap.projname AS PROJECTNAME,
     18          pr.raID AS RAREAID,
     19          ar.raName AS RAREANAME
     20          FROM allocateassociates aa,ProjecttoRAAssociation pr,
     21             addProject ap,AddResearchArea ar
     22          WHERE pr.projid = aa.projid
     23          AND aa.projid = ap.projid
     24          AND pr.raid = ar.raid
     25          GROUP BY aa.projid,ap.projname,pr.raid,ar.raname
     26       )
    --"Added outer join"
     27   full outer join  previouseffort pe
     28  on( pe.projid = PROJECTID)
     29  GROUP BY PROJECTID,PROJECTNAME,RAREAID,RAREANAME;
    
    EFFORT  PROJECTID       PROJECTNAME     RAREAID         RAREANAME
    ------- --------------- --------------- --------------- ---------------
      16.62 proj3           projname3       ra1             raname1
     132.24 proj1           projname1       ra1             raname1
       4.12 proj2           projname2       ra2             raname2
    
  • Find unmatched columns from two tables

    Hello guys,.

    I am trying to compare two tables based on a key of the indexed columns.

    Here is an example of what I'm trying to achieve:

    Table A: A_ID A_Name A_Income A_housecount
    Jess 11 9 2
    Rauny 4 6 22

    Table b: B_ID B_Income B_housecount
    11-5-2
    22 6 4
    In the example above data columns A_ID and B_Id are same in both tables. I'm trying to compare A_Income with B_Income & & A_housecount with B_housecount. The results of this series of samples would be:

    11-9-2
    11-5-2

    as income in the same id is different.

    As I have large amount of data in the two tables can you please give me some ideas on how I can get my results? Let me know if the explanation is not clear for you.

    Thanks in advance
    select hshold_id,hsold_income,hshold_size,
           'abc.' || case count(src1) when 0 then 'demo' else 'hshold' end the_source
      from (select hshold_id,hsold_income,hshold_size,
                   1 src1,
                   to_number(null) src2
              from abc.hshold
            union all
            select hshold_id,hsold_income,hshold_size,
                   to_number(null) src1,
                   2 src2
              from abc.demo
           )
     group by hshold_id,hsold_income,hshold_size
     having count(src1) != count(src2)
    

    Concerning

    Etbin

    Edited by: Etbin on 11.2.2011 18:00
    correction of alignment

Maybe you are looking for