Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Posts
    4

    Question Unanswered: NOT IN subquery problem

    I am having some probelms with a subquery.

    If I do
    SELECT id FROM list1
    I get the following back
    1,21,2,24

    If I do
    SELECT id FROM list2 WHERE id NOT IN (1,21,2,24)
    I get back
    22,23,25,26

    If I do
    SELECT id FROM list2 WHERE id IN (SELECT id FROM list1)
    I get back
    1,21,2,24

    However if I do
    SELECT id FROM list2 WHERE id NOT IN (SELECT id FROM list1)
    I get back
    no rows selected

    but I was expecting to get back 22,23,25,26

    Can anyone tell me what I'm doing wrong?

    Thanks

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: NOT IN subquery problem

    I don't know what you are doing wrong, because I just did exactly what you do above, and got the correct result:

    SQL> SELECT id FROM list1;

    ID
    ----------
    1
    21
    2
    24

    SQL> SELECT id FROM list2;

    ID
    ----------
    1
    21
    2
    24
    22
    23
    25
    26

    8 rows selected.

    SQL> SELECT id FROM list2 WHERE id NOT IN (SELECT id FROM list1);

    ID
    ----------
    22
    23
    25
    26

  3. #3
    Join Date
    Mar 2003
    Location
    Bogota
    Posts
    67
    me too

Posting Permissions

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