Compare tables, find rows that are "different"

A common problem in replication/query-extract-load scenarios is comparing two sets of data, and finding the rows that have changed or are different. A clean solution to this is less obvious than it sounds, because "different" can involve nulls (love them!/hate them!).
Consider two structurally identical tables with all data linked by a common PK:
Snapshot A Snapshot B
PK First Last State PK First Last State
1 Bob Smith AZ 1 Bob Smith AZ
2 Louise Jones FL 2 Louise Brown FL
3 Joe Jones NULL 3 Joe Jones CA
4 Joe NULL GA 4 Joe Celko NULL
5 Phill NULL AL 5 Phill NULL AL
If we are interested in tracking or processing any changes in our data, we would agree that only Rows 1 and 5 are "the same" in both sets A & B.
Because of null logic, this sql only gets me row 2 (besides being syntactically miserable with a wide table) :
select A.PK from A inner join B on A.PK = B.PK
where (A.First <> B.First) OR (A.Last <> B.Last) OR (A.State <> B.State);
So how can I select rows 2, 3, and 4? (Extra credit for for a query I can type in less than two minutes with a pair of tables that have 42 columns)
Thanks much,
Steve Pence
DBA
Wycliffe Bible Translators
Orlando
[email protected]

Sorry, my post got mangled by the white space deleterer...
A common problem in replication/query-extract-load scenarios is comparing two sets of data, and finding the rows that have changed or are different. A clean solution to this is less obvious than it sounds, because "different" can involve nulls (love them!/hate them!).
Consider two structurally identical tables with all data linked by a common PK:
Snapshot A
PK First Last State
1 Bob Smith AZ
2 Louise Jones FL
3 Joe Jones NULL
4 Joe NULL GA
5 Phill NULL AL
Snapshot B
PK First Last State
1 Bob Smith AZ
2 Louise Brown FL
3 Joe Jones CA
4 Joe Celko NULL
5 Phill NULL AL
If we are interested in tracking or processing any changes in our data, we would agree that only Rows 1 and 5 are "the same" in both sets A & B.
Because of null logic, this sql only gets me row 2 (besides being syntactically miserable with a wide table) :
select A.PK from A inner join B on A.PK = B.PK
where (A.First <> B.First) OR (A.Last <> B.Last) OR (A.State <> B.State);
So how can I select rows 2, 3, and 4? (Extra credit for a query I can type in less than two minutes with a pair of tables that have 42 columns)
Thanks much,
Steve Pence
DBA
Wycliffe Bible Translators
Orlando
[email protected]

Similar Messages

  • TS2972 used to be able to pick out which songs in iTunes in my computer were not on a 2nd computer on homeshare in iTunes 10.  Now with V11, cant find the button that compares two libraries and finds the songs that are different.  Anyone know how to do th

    Used to be able to pick out which songs in iTunes in my computer were not on a 2nd computer on homeshare in iTunes 10.  Now with V11, cant find the button that compares two libraries and finds the songs that are different.  Anyone know how to do this now?

    Jneklason wrote:
    ~snip~
    I know this email is confusing and really hard to understand...perhaps now you will know how i've been feeling--lost and confused with all the mis-information, with a hit and miss phone, and out of time with all the 1 1/2 hr to 2 hrs EACH wasted on this issue.
    On top of all this, I can't even find out how to file a complaint with anyone higher up than Customer Service.
    I hate to tell you this, but you didn't write an email. You wrote a discussion post on the Verizon Wireless Community forum which is a public peer to peer forum. Unfortunately since you didn't mark your post as a question, the VZW reps that roam this community won't ever see your post. Before you re-post it, don't. Duplicate posts get removed from the community.
    I see there were several missteps both by the reps and yourself in your post. First you should have insisted on returning the phone within the 14 day return policy period. Second which Samsung Galaxy mini model did you purchase? The S3 mini or the S4 mini? Did you do any research prior to deciding on this device. The reps at that time deflected the easiest course of action, by trying to get you to replace the phone under insurance instead of returning the phone. The Early Edge payment option requires the current phone on the line using the early Edge must be returned to Verizon Wireless. Did you once considered going to a third party site like Swappa to purchase a gently used device for your daughter?

  • OWB mappings to skip rows that are in error and continue processing

    OWB mappings to skip rows that are in error and continue processing.
    1) Enter a record into an error log
    2) Skip rows that are in error
    3) and continue processing
    Type of information could be needed in the error log:
    SY_LOG_ERROR_KEY
    ERROR_TIMESTAMP
    MAP_NAME
    SOURCE_RECORD
    ERROR_CODE
    ERROR_MESSAGE
    ERROR_NOTES
    Example:
    If the source table has five records, in that 3 records has some error.
    When I run the OWB mapping to load the source data to target table, OWB should skip the 3 record and load all the remaining record. This is our requirement.
    Another think I want to store the error record details in a error log table.
    Can u plz tell me whether it is possible in OWB. If not means please give some suggestion to do this.

    Hi,
    thanks for ur help, As is OWB version is 10.2.0 so for set based it is not working. with your idea i create a POST PROCESSING MAPPING. it is now working fine.
    Step 1:
    Create a table MAP_ERROR_LOG.
    Script:
    CREATE TABLE MAP_ERROR_LOG
    ERROR_SEQ NUMBER,
    MAPPING_NAME VARCHAR2(32 BYTE),
    TARGET_TABLE VARCHAR2(35 BYTE),
    TARGET_COLUMN VARCHAR2(35 BYTE),
    TARGET_VALUE VARCHAR2(100 BYTE),
    PRIMARY_TABLE VARCHAR2(100 BYTE),
    ERROR_ROWKEY NUMBER,
    ERROR_CODE VARCHAR2(12 BYTE),
    ERROR_MESSAGE VARCHAR2(2000 BYTE),
    ERROR_TIMESTAMP DATE
    TABLESPACE ODS_D1_AA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 80K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    Step 2:
    Create a sequence MAP_ERROR_LOG_SEQ
    CREATE SEQUENCE MAP_ERROR_LOG_SEQ START WITH 1 INCREMENT BY 1
    Step 3:
    Create a procedure PROC_MAP_ERROR_LOG through OWB.
    In this i have used 3 cursor, first cursor is used to check the count of error messages for the corresponding table(WB_RT_ERROR_SOURCES).
    The second cursor is used to get the oracle error and the primary key values.
    The third cursor is used for get the ORACLE DBA errors such as "UNABLE TO EXTEND THE TABLESPACE" for this type errors.
    CREATE OR REPLACE PROCEDURE PROC_MAP_ERROR_LOG(MAP_ID VARCHAR2) IS
    --initialize variables here
    CURSOR C1 IS
    SELECT COUNT(RTA_IID) FROM OWBREPO.WB_RT_ERROR_SOURCES
    WHERE RTA_IID =( SELECT MAX(RTA_IID) FROM OWBREPO.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    V_COUNT NUMBER;
    CURSOR C2 IS
    SELECT A.RTE_ROWKEY ERR_ROWKEY,SUBSTR(A.RTE_SQLERRM,1,INSTR(A.RTE_SQLERRM,':')-1) ERROR_CODE,
    SUBSTR(A.RTE_SQLERRM,INSTR(A.RTE_SQLERRM,':')+1) ERROR_MESSAGE,
    C.RTA_LOB_NAME MAPPING_NAME,SUBSTR(B.RTS_SOURCE_COLUMN,(INSTR(B.RTS_SOURCE_COLUMN,'.')+1)) TARGET_COLUMN,
    B.RTS_VALUE TARGET_VALUE,C.RTA_PRIMARY_SOURCE PRIMARY_SOURCE,C.RTA_PRIMARY_TARGET TARGET_TABLE,
    C.RTA_DATE ERROR_TIMESTAMP
    FROM OWBREPO.WB_RT_ERRORS A,OWBREPO.WB_RT_ERROR_SOURCES B, OWBREPO.WB_RT_AUDIT C
    WHERE C.RTA_IID = A.RTA_IID
    AND C.RTA_IID = B.RTA_IID
    AND A.RTA_IID = B.RTA_IID
    AND A.RTE_ROWKEY =B.RTE_ROWKEY
    --AND RTS_SEQ =1  
    AND B.RTS_SEQ IN (SELECT POSITION FROM ALL_CONS_COLUMNS A,ALL_CONSTRAINTS B
    WHERE A.TABLE_NAME = B.TABLE_NAME
    AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
    AND A.TABLE_NAME =MAP_ID
    AND CONSTRAINT_TYPE ='P')
    AND A.RTA_IID =(
    SELECT MAX(RTA_IID) FROM OWBREPO.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    CURSOR C3 IS
    SELECT A.RTE_ROWKEY ERR_ROWKEY,SUBSTR(A.RTE_SQLERRM,1,INSTR(A.RTE_SQLERRM,':')-1) ERROR_CODE,
    SUBSTR(A.RTE_SQLERRM,INSTR(A.RTE_SQLERRM,':')+1) ERROR_MESSAGE,
    C.RTA_LOB_NAME MAPPING_NAME,SUBSTR(B.RTS_SOURCE_COLUMN,(INSTR(B.RTS_SOURCE_COLUMN,'.')+1)) TARGET_COLUMN,
    B.RTS_VALUE TARGET_VALUE,C.RTA_PRIMARY_SOURCE PRIMARY_SOURCE,C.RTA_PRIMARY_TARGET TARGET_TABLE,
    C.RTA_DATE ERROR_TIMESTAMP
    FROM OWBREPO.WB_RT_ERRORS A,OWBREPO.WB_RT_ERROR_SOURCES B, OWBREPO.WB_RT_AUDIT C
    WHERE C.RTA_IID = A.RTA_IID
    AND A.RTA_IID = B.RTA_IID (+)
    AND A.RTE_ROWKEY =B.RTE_ROWKEY (+)
    AND A.RTA_IID =(
    SELECT MAX(RTA_IID) FROM OWBREPO.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    -- main body
    BEGIN
    DELETE ED_ODS.MAP_ERROR_LOG WHERE TARGET_TABLE ='"'||MAP_ID||'"';
    COMMIT;
    OPEN C1;
    FETCH C1 INTO V_COUNT;
    IF V_COUNT >0 THEN
    FOR REC IN C2
    LOOP
    INSERT INTO ED_ODS.MAP_ERROR_LOG
    (Error_seq ,
    Mapping_name,
    Target_table,
    Target_column ,
    Target_value ,
    Primary_table ,
    Error_rowkey ,
    Error_code ,
    Error_message ,
    Error_timestamp)
    VALUES(
    ED_ODS.MAP_ERROR_LOG_SEQ.NEXTVAL,
    REC.MAPPING_NAME,
    REC.TARGET_TABLE,
    REC.TARGET_COLUMN,
    REC.TARGET_VALUE,
    REC.PRIMARY_SOURCE,
    REC.ERR_ROWKEY,
    REC.ERROR_CODE,
    REC.ERROR_MESSAGE,
    REC.ERROR_TIMESTAMP);
    END LOOP;
    ELSE
    FOR REC IN C3
    LOOP
    INSERT INTO ED_ODS.MAP_ERROR_LOG
    (Error_seq ,
    Mapping_name,
    Target_table,
    Target_column ,
    Target_value ,
    Primary_table ,
    Error_rowkey ,
    Error_code ,
    Error_message ,
    Error_timestamp)
    VALUES(
    ED_ODS.MAP_ERROR_LOG_SEQ.NEXTVAL,
    REC.MAPPING_NAME,
    REC.TARGET_TABLE,
    REC.TARGET_COLUMN,
    REC.TARGET_VALUE,
    REC.PRIMARY_SOURCE,
    REC.ERR_ROWKEY,
    REC.ERROR_CODE,
    REC.ERROR_MESSAGE,
    REC.ERROR_TIMESTAMP);
    END LOOP;
    END IF;
    CLOSE C1;
    COMMIT;
    -- NULL; -- allow compilation
    EXCEPTION
    WHEN OTHERS THEN
    NULL; -- enter any exception code here
    END;

  • VBScript - Identifying Rows that are too large for a page

    I am trying to write a VBScript that will identify rows that are too large to fit on a page.
    So far I have:
    Sub IfRowIsTooBigBreakAcrossPage()
    'Use to track number of tables in the document
    Dim t As Integer
    'Use to track number of rows in a Table
    Dim r As Integer
    'Get the number of tables in the document
    t = ActiveDocument.Tables.Count
    For i = 1 To t
    'Get the number of rows in a table
    r = ActiveDocument.Tables(i).Rows.Count
    For n = 1 to r
    If ActiveDocument.Tables(i).Rows(n).Height > 6 Then
    Active Document.Tables(i).Rows(n).AllowBreakAcrossPages = True
    End If
    Next
    Next
    End Sub
    I am having a hard time just getting this to run.   This is meant to run on tables that have been exported from IBM Doors.  I'm not sure if that [having been exported from Doors] is the issue or if I'm just missing something when it comes to the
    Rows attributes.
    Any help is appreciated!

    Hi David,
    I'm afraid that it is not the correct forum about this issue, since this forum is to discuss Visual Basic.
    For some reason, I can't help you to move this case to Scripting forum, please feel free to open a new thread in that forum for better response:
    http://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG
    Thanks for your understanding.
    Best regards,
    Franklin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Count rows that are max timestamp

    Hi,
    I'm trying to run a query that will count only rows that are max timestamp.
    i have a submit table which has dates of submissions, however some application numbers have multiple rows in this table. I need to count only one row per application and it has to be the latest submission data.
    I have tried a subquery and its not working, I'm stuck at this point.
    Thanks for help :)
    example table
    pk app # submit_date
    12 test-1 02222011 13:30
    13 test-2 02232011 09:45
    14 test-1 02232011 09:51
    how do i count rows but based on max timestamp?

    select
    count(s.pk)
    from
    submit s
    where exists (select s1.app#, max(s1.submit_date) from submit s1 group by s1.app#)
    I dont really understand what you are doing there.
    SQL> WITH T
      2       AS (SELECT 12 pk, 'TEST-1' app#, SYSDATE submit_date FROM DUAL
      3           UNION ALL
      4           SELECT 13 pk, 'TEST-2' app#, SYSDATE + 1 submit_date FROM DUAL
      5           UNION ALL
      6           SELECT 14 pk, 'TEST-1' app#, SYSDATE + 2 submit_date FROM DUAL)
      7  SELECT * FROM T;
            PK APP#   SUBMIT_DA
            12 TEST-1 23-FEB-11
            13 TEST-2 24-FEB-11
            14 TEST-1 25-FEB-11
    SQL> WITH T
      2       AS (SELECT 12 pk, 'TEST-1' app#, SYSDATE submit_date FROM DUAL
      3           UNION ALL
      4           SELECT 13 pk, 'TEST-2' app#, SYSDATE + 1 submit_date FROM DUAL
      5           UNION ALL
      6           SELECT 14 pk, 'TEST-1' app#, SYSDATE + 2 submit_date FROM DUAL)
      7  SELECT   pk, app#
      8    FROM   (SELECT pk, app#, ROW_NUMBER () OVER (PARTITION BY app# ORDER BY submit_date DESC) rn
    FROM T)
      9   WHERE   rn = 1;
            PK APP#
            14 TEST-1
            13 TEST-2
    SQL>

  • How to get average between rows that are null?

    I need to get the average between the 2 positive numbers.
    Then update the table with the average for those rows that are NULL between the 2 positive numbers.
    The average will come (78+89)/2= 83.5. Round it to 84.
    Then it will be:
    6-4-13       84
    6-5-13        84
    6-6-13        84
    As for 6-9-13 and 6-10-13, those values will still be NULL.
    {code}
    create table dummy( tmestmp date
    ,maxtemp number(4,0));
    insert into dummy(tmestmp,maxtemp) values(to_date('20130601','YYYYMMDD'),70);
    insert into dummy(tmestmp,maxtemp) values(to_date('20130602','YYYYMMDD'),81);
    insert into dummy(tmestmp,maxtemp) values(to_date('20130603','YYYYMMDD'),78);
    insert into dummy(tmestmp) values(to_date('20130604','YYYYMMDD'));
    insert into dummy(tmestmp) values(to_date('20130605','YYYYMMDD'));
    insert into dummy(tmestmp) values(to_date('20130606','YYYYMMDD'));
    insert into dummy(tmestmp,maxtemp) values(to_date('20130607','YYYYMMDD'),89);
    insert into dummy(tmestmp,maxtemp) values(to_date('20130608','YYYYMMDD'),91);
    insert into dummy(tmestmp) values(to_date('20130609','YYYYMMDD'));
    insert into dummy(tmestmp) values(to_date('20130610','YYYYMMDD'));
    {/code}
    I need the output to look like this:
    Header 1
    Header 2
    01-JUN-13
    02-JUN-13
    03-JUN-13
    04-JUN-13
    05-JUN-13
    06-JUN-13
    07-JUN-13
    08-JUN-13
    09-JUN-13
    10-JUN-13
    70
    81
    78
    84
    84
    84
    89
    91
    null
    null
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    "CORE 10.2.0.4.0 Production"
    TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Suggestions?
    TIA.
    Steve42

    select  tmestmp,
            nvl(
                maxtemp,
                round(
                       last_value(maxtemp ignore nulls)
                         over(order by tmestmp) +
                       first_value(maxtemp ignore nulls)
                         over(order by tmestmp
                              rows between 1 following and unbounded following
                      ) / 2
               ) maxtemp
      from  dummy
    TMESTMP                MAXTEMP
    06/01/2013 00:00:00         70
    06/02/2013 00:00:00         81
    06/03/2013 00:00:00         78
    06/04/2013 00:00:00         84
    06/05/2013 00:00:00         84
    06/06/2013 00:00:00         84
    06/07/2013 00:00:00         89
    06/08/2013 00:00:00         91
    TMESTMP                MAXTEMP
    06/09/2013 00:00:00
    06/10/2013 00:00:00
    10 rows selected.
    SQL>
    SY.

  • How can I find photos that are not assigned to any collection?

    Hi !
    I'm using LR 5.7.1 on a Mac.
    When I've retouched raw pictures with PS CC (and do not need the PSD file any longer) I export the PSD (that is in my catalog) as JPG and let it add to my catalog automatically. After that I delete the PSD file. That works fine.
    But .... the new JPG file is not assigned to any collection. That's no problem unless I forget to do it manually after that export (and import).
    That brings me to my question.
    How can I find photos that are not assigned to any collection?
    I tried it with a smart collection after I found nothing suitable in library filter. The search criteria I tried are Source -> Collection with any of the conditions. One with an empty value field, then with just a space and so on.
    Has anybody a good hint for me?
    Thomas

    You can also add numbers if you have collections that don't use alphabet characters.

  • The "Search" function box doesn't find things that are there! Why?!

    The "Search" function box doesn't find things that are there! Why? Eg: It doesnt show all my Sent and Received emails, but it will find an email that I half wrote and deleted. Unsure why or how to explain more fully.
    I also don't understand if I type in "James email" or "J" into the search box and all the J / James stuff appears but it doesn't show the emails I know have been sent and I know are somewhere because I rang "James" up to check, but the search box shows random thing I am NOT looking for, even if I type in fully what I am looking for and test it by typing in full titles of things.
    It also doesn't store all my sent emails in "Sent" box. Confused! I'm not sure if the "Search" box just isn't up to the job or if it is broken / i'm doing something wrong? Maybe the email address I use isn't set up properly?

    This can happen sometimes if the cache is not cleared correctly when items are not deleted from your device.
    The only solution to this is to do a restore to clean out the cache file.

  • How can I write into a table cell (row, column are given) in a databae?

    How can I write into a table cell (row, column are given) in a database using LabVIEW Database Toolkit? I am using Ms Access. Suppose I have three columns in a table, I write 1st row of 1st column, then 1st row of 3rd column. The problem I am having is after writing the 1st row 1st column, the reference goes to second row and if I write into 3rd column, it goes to 2nd row 3rd column. Any suggestion? 
    Solved!
    Go to Solution.

    When you do a SQL INSERT command, you create a new row. If you want to change an existing row, you have to use the UPDATE command (i.e. UPDATE tablename SET column = value WHERE some_column=some_value). The some_column could be the unique ID of each row, a date/time, etc.
    I have no idea what function to use in the toolkit to execute a SQL command since I don't use the toolkit. I also don't understand why you just don't do a single INSERT. It would be much faster.

  • I recently burned a photos on a few DVDs using finder. Now I have unwanted files in the sidebar of the finder window that are unresponsive and can not be deleted. I have 3 "untitled DVD " files and 1 "spaces app"

    I recently burned  photos on a few DVDs using finder. Now I have unwanted files in the sidebar of the finder window that are unresponsive and can not be deleted. I have 3 "untitled DVD " files and 1 "spaces app" file. The unwanted files occur under "Places"
    What do i have to do to clean up my  finder sidebar?
    HJ

    Hold down the command button while dragging he items out of the finder window.

  • My zagg key board connects but the keys I type either don't type character, type 2 characters that are different when I hit only 1 key, or doesn't type at all. Is there a way to reset zagg keyboard to factory settings?

    My zagg key board connects but the keys I type either don't type character, type 2 characters that are different when I hit only 1 key, or doesn't type at all. Is there a way to reset zagg keyboard to factory settings?

    Recharging is a good thing to try. They do start to act odd when the battery gets low. Beyond that, just like Tom says, contact Zagg. I have one of their keyboards and the company has wonderful customer service.

  • Where do I find files that are saved "to this device"

    Where do I find files that are saved "to this device"?
    Thanks

    You can not download files to the device through safari.
    Photos and PDFs can be saved in photo and PDFs in iBook.
    Files can be saved through iTunes on a computer, they have to be placed in the app used to view them.
    What is it you are trying to do?

  • How to finds applications that are still running?

    How do I find applications that are running on my computer?  I can't install a new version of Google Drive because I get the message that this application is open.  When I bring up the panel to do a force quit I do not see that application listed.  Once I find the app running how do I quit it?
    Thanks for any tips.
    Bryan

    Use Activity Monitor (in /Applications/Utilities). After opening it, go to View menu (on the menu bar) > All Processes, and quit the processes related to the apps that the installer needs.
    Another way is to start up in safe mode by holding the Shift key while your Mac is starting. This allows you to install any application without any problem, as no third-party apps are running

  • SQL query to find differences (changes) between tables (from one table) where field names are different

    Hi All,
    I am looking to create a view which returns new or modified data (differences) based on a comparison between two tables.
    The EMP_SOURCE table stores all employee data including duplicate staff numbers (STAFFNO):
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    ) ON [PRIMARY]
    GO
    The EMP table stores unique staff numbers. This is the table used by the application.
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL,
    CONSTRAINT [PK_EMP] PRIMARY KEY CLUSTERED
    [EMP_ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    We are looking to migrate data from EMP_SOURCE to EMP but only records which are new in EMP_SOURCE and do not exist in EMP or records which are different in EMP_SOURCE from EMP.
    EMP_SOURCE:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    John Smith
    Manager
    London
    UK
    1087
    Beth King
    Analyst
    New York
    USA
    2095
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Beth King
    Junior
    Washington
    USA
    2095
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    EMP:
    EMP_ID
    EMP_NAME
    EMP_TITLE
    EMP_OFFICE
    EMP_COUNTRY
    EMP_NUMBER
    1
    John Smith
    Manager
    London
    UK
    1087
    2
    Beth King
    Analyst
    New York
    USA
    2095
    3
    Karl Bent
    Manager
    Washington
    USA
    1106
    Based on the above comparison, EMP_SOURCE table has the following differences:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Differences in red. Beth King should be completely ignored because of duplicate staff numbers (EMP_NUMBER).
    Any help to create a view which returns only the differences from EMP_SOURCE would be appreciated.
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');

    HI Manc !
    You may use the below code to get your desired output;
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    GO
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');
    SELECT FULLNAME,JOBTITLE,LOCATION,COUNTRY,STAFFNO FROM EMP_SOURCE
    EXCEPT
    SELECT EMP_NAME,EMP_TITLE,EMP_OFFICE,EMP_COUNTRY,EMP_NUMBER FROM Emp
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • How can I find photos that are not in any event?

    Help!  I have finally, after a decade or so, organized my events and emptied out the trash and gotten rid of duplicates. Round of applause, please.  How can I find out if there are sneaky pictures that are NOT in any particular event (please dont say by showing all photos and just going through each one!)

    You can't because every photo is in an Event already. That's how iPhoto works. Every photo is in the LIbrary. The Library is built upon events. SO if it's in iPhoto, it's in the Library and in an Event.
    Albums are different, as they refernce photos in the LIbrary. It;s perfectly possilbe to have a photo in the Library but not in an album.

Maybe you are looking for

  • Mac Pro Windows 7 Fail

    Hi I have a late 2007 8 core Mac Pro it has been living mostly happily with Snow Leopard and Windows XP. I need 64 bit windows on it, but since it's not supported on that machine I decided to take the route of installing Win 7 x86 first. I I wanted t

  • Cross Docking in SAP R/3 ECC 6.0

    Folks, I'm struggling to make 2-step w/ planned cross docking work. Basically, unable to connect the planned with the candidate document. Here is the scenario: 1. (Candidate) Outbound delivery created with a delivery date / time of 09/04/08 - 10:00 (

  • How to set the size of folder in KM

    Hi everyone, This is Nagaraja.........i am new to SAP Enterprise Portal and I have created a folder in Knowledge Management and i want to restrict the number of files uploaded into that folder by enduser. i.e., i want to set the size of the folder. c

  • ITouch Random Quitting

    Hello, I'm wondering if anyone can help me. A problem that has been frequent for me is safari randomly quitting when I'm using it. It'll be loading something, then the screen will just go black and I'll see the home screen. It will say safari can't f

  • InDesign Crashes, the file I was working on doesn't recover, and won't let me open because InDesign says it's already open.

    This has happened a few times, I would be working on a project, InDesign crashes, but doesn't recover it. Instead when I try to open the file, it says it can't be opened because it's already open by another user (there are no other users) I'll restar