Two Table Compare

Posted on 2012-08-24
Last Modified: 2012-08-24
I am needing to compare two tables in SAS (using SQL sytax) to find out what records in Table A is in Table B, and if they are not in Table B, then I want to add a column to the query to mark them as 'New'.

      create table TableC as
      select a.*, 'New' as Type
      from TableA a
      where not in (select id from TableB);

Obviously my query is currently only getting those records that don't match and creating the new column...but there has to be a way to do this all in one query, or maybe I'm wrong.
Question by:Lee R Liddick Jr
    1 Comment
    LVL 75

    Accepted Solution

    Something like this perhaps:
    SELECT  a.*,
            CASE WHEN IS NULL THEN 'New'
                 ELSE NULL
            END AS Type
    FROM    TableA a
            LEFT JOIN TableB b ON =

    Open in new window


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article describes some very basic things about SQL Server filegroups.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now