Results 1 to 3 of 3

Thread: Exclusive Selection

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Exclusive Selection

    Hello.
    I'm working with a access v.2 database.

    This are 2 tables from where I need to collect some data:

    Table Account
    |ID|Name
    |1 |James
    |2 |Stewart
    |3 |Bill
    |4 |Bob

    Table AccountTMP
    |ID|
    |1 |
    |4 |

    The fields ID are PK on both tables.

    How do I select the data not existing on the AccountTMP table (ID=2, ID=3), based on the Account fields?

    Thank you.
    Last edited by RS_Arm; Sep 3rd, 2007 at 08:52 AM.

  2. #2

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Exclusive Select

    should it be something like this?

    Select account.id
    from account
    where account.id not in
    (Select * from AccountTMP)

    Thank you.
    Last edited by RS_Arm; Sep 3rd, 2007 at 08:52 AM.

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Exclusive Selection

    I would consider a join operation first - it's more natural for SQL to process.

    Code:
    Select * From Account AC
    Left Join AccountTmp AT on AT.Id=AC.Id
    Where AT.Id is null
    If you want to test your method though - the proper syntax would be more like:

    Code:
    Select account.id
    from account
    where account.id not in
    (Select Id from AccountTMP)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width