Compare two tables

  • Hi all,

    I have table called 'tblMaster' with one field 'ItemCode' and another table is tblTrans with one field 'ItemCode'

    tblMaster Records

    ItemCode

    I1

    I2

    I3

    I4

    I5

     

    tblTrans Records

    I2

    I3

     

     

    I want a query that should return the records from tblMaster- I1,I4,I5

    Any sample query ?

    Thanks

    Rgds

    Senk

     

     

     

     

     

     

     

  • This should work:

    SELECT ItemCode

    FROM tblMaster

    WHERE ItemCode NOT IN (SELECT ItemCode FROM tblTrans)


    Enjoy!

    A Brown

    Manage all of your backups in one simple job using this script.

  • Thank you..

  • Or you can use this (I like it more than IN clause and at least sometimes it works a lot quicker - didn't do any extensive testing though):

    SELECT M.ItemCode

    FROM tblMaster M

    LEFT JOIN tblTrans T ON T.ItemCode=M.ItemCode

    WHERE T.ItemCode IS NULL

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

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