How can i get records from table A which is not in B in sql server. eg A-B

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shafi hashmi
    New Member
    • Dec 2010
    • 14

    #1

    How can i get records from table A which is not in B in sql server. eg A-B

    Hi dear i have two table in sql like,
    A={123}
    B={3}
    i want to perform
    A-B={12}

    i have writeen this qry
    SELECT a.code FROM A LEFT INNER JOIN B ON b.code AND a.name='shafi'
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    you are very close, the left join is the answer, but you want to select all the mismatches, that is where there is no b.code -
    SELECT a.code FROM A LEFT OUTER JOIN B ON a.code = b.code
    where b.code is null

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      If you're just looking for records in A that are not in B, you can also use NOT EXISTS...

      Good Luck!!!

      ~~ CK

      Comment

      Working...