compared two table with

  • I have module log have DOB and Name and employee table DOB and Name. I want to get the result who are in the employee tables but not in the module log . Thanks.

  • Be careful with nulls but try something like:

    select *

    from dbo.Employees E

    where not exists (select *

      from dbo.ModuleLog L

      where L.EmployeeName = E.EmployeeName

       and L.DOB = E.DOB)

    or

    select E.*

    from dbo.Employees E

     left join dbo.ModuleLog L on E.EmployeeName = L.EmployeeName and E.DOB = L.DOB

    where L.EmployeeName is null

     

  • Thanks. It is well done.

  • or if you are on sql 2005 you can use

    select EmployeeName ,DOB

    from Employees

    EXCEPT

    select EmployeeName ,E.DOB

    from modulelog

    Probably more efficient

    www.sql-library.com[/url]

  • > Probably more efficient

    Did you compare?

    _____________
    Code for TallyGenerator

  • nope thats why i said probably.

    Would be interesting to see, if you have time.

    I suspect it would be faster because no joins are required particulary no outer joins.

    Perhaps the original poster could do a test and let us know how the 3 methods compare.

    www.sql-library.com[/url]

  • I did not have SQL server 2005. I used the first method.

     

    select *

    from dbo.Employees E

    where not exists (select *

      from dbo.ModuleLog L

      where L.EmployeeName = E.EmployeeName

       and L.DOB = E.DOB).

     

    Since I felt no join is better. It is fast. Thanks.

Viewing 7 posts - 1 through 6 (of 6 total)

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