Compare data sets and find matches.

  • I need to compare two sets of data. The first data set is a single column from the database. The second data set is not in the database so I assume it will need to be referenced in a cache file.  The two sets do not have the same number of entries. The result needs to show only matching data. Any idea which direction I can go with this? Thanks.

  • Maybe something like this? (Might get shredded for this one, but live & learn!)
    /* populate dummy table */
    SELECT PatientID, Gender, Birthdate
    INTO #Dummy
    FROM dbo.Patient p
    WHERE p.BirthDate > '1990-01-01';

    /* find missing records */
    SELECT *
    FROM dbo.Patient p
    WHERE NOT EXISTS (SELECT 1 FROM #Dummy d
                        WHERE d.PatientID = p.PatientID);

  • mcbv - Tuesday, September 19, 2017 1:25 PM

    I need to compare two sets of data. The first data set is a single column from the database. The second data set is not in the database so I assume it will need to be referenced in a cache file.  The two sets do not have the same number of entries. The result needs to show only matching data. Any idea which direction I can go with this? Thanks.

    And how are we supposed to help based on just what you have posted?  Could you answer a question just with what you posted with no knowledge of the database, data, or system?

  • I guess I'd import the data that's not in the database, and depending on how they need to "match", I'd use an INNER JOIN between the 2 tables if only 1 column needs to be matching, or INTERSECT if the entire row needs to match in both tables:
    https://docs.microsoft.com/en-us/sql/t-sql/language-elements/set-operators-except-and-intersect-transact-sql

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply