Results 1 to 5 of 5

Thread: tsql (not in subquery) help on syntax

  1. #1
    Join Date
    May 2005
    Posts
    111

    tsql (not in subquery) help on syntax

    I run the following with the "IN" clause and receive all but 2 rows that don't exist in both tables. I try running the same query with "NOT IN" to identify the 2 rows that don't match and instead receive a nullset. Please help!


    select a.employeeIdNum

    from phonebook.lawsonextract a
    where a.employeeidNum is not null

    and a.employeeidNum NOT IN (select b.employeeIdNum from phonebook.employeelist b)

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select a.employeeIdNum from (select employeeIdNum from phonebook.lawsonextract where employeeIdNum is not NULL) a where a.employeeidNum NOT IN (select b.employeeIdNum from phonebook.employeelist b)

  3. #3
    Join Date
    May 2005
    Posts
    111

    negative ghost rider

    Nope---sorry same resultset

  4. #4
    Join Date
    Dec 2004
    Posts
    502
    The pattern is full

    You probably have some NULL values for the "employeeIdNum" column in the "employeelist" table. If you use an "IN" comparison against NULL values, SQL Server will by default evaluate that as an unknown, or a NULL. Therefore, its better if you use the EXISTS or NOT EXISTS comparison:

    select a.employeeIdNum
    from phonebook.lawsonextract a
    where a.employeeidNum is not null
    and NOT EXISTS (select 1 from phonebook.employeelist b
    where a.employeeidNum = b.employeeIdNum)

  5. #5
    Join Date
    May 2005
    Posts
    111

    You The Man --- Nosepicker!!!

    that worked---thanks to both of you for the help. -allen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •