How to selected NON Matched records using <> ?

  • Hi i want to select the records from TableB

    which is NOT IN Table A

  • It really depends on the situation, but if you do a left join on the primary table and look for nulls in the secondary table it will return all rows from the primary table with no matching records in the secondary table.

    Select B.*

    FROM Tableb B LEFT JOIN

    Tablea A ON

    B.col1 = A.col1 AND

    B.col2 = A.col2

    Where A.col IS NULL

    Or if it is just a singe column you could do this.

    Select * from TableB

    where col NOT IN (Select col from TableA)

  • Or, you can use EXCEPT:

    SELECT * FROM TABLEA

    EXCEPT SELECT * FROM TABLEB;

    Look in BOL for further information,

    Jeff

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 3 posts - 1 through 2 (of 2 total)

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