Results 1 to 11 of 11
  1. #1
    dukect is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    5

    Not In Clause

    I have the query as below:



    SELECT FAccount from T5
    where FAccount not in (
    select Account from t3)

    I know FAccount # 424337466884 in T5 is not in T3, so the query should at least return 424337466884. But this query returns nothing.

    Please help. Thanks in advance.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    look at your field sizes in both your tables. they're both 20, but one is following your orders and one is not. the only difference is that T5 has Unicode Compression turned off. T5 is cutting off data to the length of the acct numbers. But T3 is giving you the extra spaces you deserve.

    Click that line in design view and press F1 to read about it. That's probably the reason for the query error.

  3. #3
    dukect is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    5
    Quote Originally Posted by ajetrumpet View Post
    look at your field sizes in both your tables. they're both 20, but one is following your orders and one is not. the only difference is that T5 has Unicode Compression turned off. T5 is cutting off data to the length of the acct numbers. But T3 is giving you the extra spaces you deserve.

    Click that line in design view and press F1 to read about it. That's probably the reason for the query error.
    Thank you very much for your help.

    I've turned Unicode Compression on both t3 and t5 off and trimed the data in T3, still receive the same result.

    If I modify the query from not in to in, the result turns out correct.

    Just don't know why, very strange.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if all else fails, use TRIM() to get rid of trailing and leading spaces in your data. Then you can use whatever subquery statement you want, and the blanks won't matter.

  5. #5
    dukect is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    5
    Quote Originally Posted by ajetrumpet View Post
    if all else fails, use TRIM() to get rid of trailing and leading spaces in your data. Then you can use whatever subquery statement you want, and the blanks won't matter.

    I did try to trim both column in t3 and t5, can't get it work. Very frustrate.

    Thanks.

  6. #6
    LillMcGill is offline Dagny fan
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Southern USA
    Posts
    70
    I is your nulls

    SELECT T5.FAccount
    FROM T5
    WHERE (((T5.[FAccount]) Not In (select Account from t3 where t3.Account is not null)));

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by dukect View Post
    I did try to trim both column in t3 and t5, can't get it work. Very frustrate.

    Thanks.
    hmmmm...maybe that's because there is a distinct field size?

    another alternative would be to use REPLACE() to get rid of the " " characters and replace them with "" characters. That surely should work!

    at any rate, good luck with it.

  8. #8
    LillMcGill is offline Dagny fan
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Southern USA
    Posts
    70
    Is my previous post invisible?
    Not In (select Account from t3 where t3.Account is not null)));

  9. #9
    dukect is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    5
    Quote Originally Posted by LillMcGill View Post
    Is my previous post invisible?
    That works. But do you know why?

    Thank you very very much.

  10. #10
    LillMcGill is offline Dagny fan
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Southern USA
    Posts
    70
    NULL=Unknown
    So basically, you were saying SELECT something WHERE not in a list that includes unknown.

    Everything potentially = the mystery value.

    That is my understanding of the trouble with tribbles. I mean the trouble with the NOT IN operator.

  11. #11
    dukect is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    5
    Quote Originally Posted by LillMcGill View Post
    NULL=Unknown
    So basically, you were saying SELECT something WHERE not in a list that includes unknown.

    Everything potentially = the mystery value.

    That is my understanding of the trouble with tribbles. I mean the trouble with the NOT IN operator.
    Got it. Thank again.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. TOP clause not working
    By fabilewk in forum Queries
    Replies: 5
    Last Post: 08-02-2011, 12:19 PM
  2. Using the TOP clause
    By WSlepecki in forum Queries
    Replies: 1
    Last Post: 04-08-2011, 06:59 AM
  3. Where clause
    By Amerigo in forum Queries
    Replies: 2
    Last Post: 03-30-2011, 07:34 AM
  4. IIF clause
    By Peljo in forum Queries
    Replies: 2
    Last Post: 02-05-2008, 11:22 AM
  5. Help on WHERE clause
    By QBCM in forum Programming
    Replies: 1
    Last Post: 12-19-2005, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums