?? on Finding only fields that dont match in two different tables

  • Hi

    I have two table People and Employee, both have firstname and lastname as fields

    I want to display only the names that don't match on firstname and lastname

    Thanks

    Joe

  • jbalbo (2/12/2015)


    Hi

    I have two table People and Employee, both have firstname and lastname as fields

    I want to display only the names that don't match on firstname and lastname

    Thanks

    Joe

    Hello Joe, what have you tried so far?

    So what you want is to find where a firstname / lastname combination is in one table but not the other?

    Look at full join.

  • Sorry I left out that the tables do have an ID field to match on

    I did come up with this but wondering if there was a better way?

    Thanks

    SELECT people.id, people.[First Name] AS EFirst, people.[Last Name] AS ELast,

    people_Identifiers.[Number/Code] AS ENumber, Employee.FirstName AS UFirst, Employee.LastName AS ULast,

    Employee.EmployeeNumber AS UNumber

    FROM people INNER JOIN

    people_Identifiers ON people.ObjectID = people_Identifiers.Person INNER JOIN

    Employee ON people_Identifiers.[Number/Code] = Employee.EmployeeNumber AND

    people.[First Name] <> Employee.FirstName AND people.[Last Name] <> Employee.LastName

  • I would change the join conditions.

    SELECT people.id,

    people.[First Name] AS EFirst,

    people.[Last Name] AS ELast,

    people_Identifiers.[Number/Code] AS ENumber,

    Employee.FirstName AS UFirst,

    Employee.LastName AS ULast,

    Employee.EmployeeNumber AS UNumber

    FROM people

    INNER JOIN people_Identifiers ON people.ObjectID = people_Identifiers.Person

    INNER JOIN Employee ON people_Identifiers.[Number/Code] = Employee.EmployeeNumber

    AND (people.[First Name] <> Employee.FirstName

    OR people.[Last Name] <> Employee.LastName)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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