Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513

    SQL WHERE ... IN selects "any", what selects "all"

    I have tables with a one-to-many relationship
    the following selects records that match "any" of the values (...correct?)

    Code:
    SELECT tblManufacturers.*
     FROM tblManufacturers
     WHERE tblManufacturers.Catagory IN (value1,value2,...);
    simple question:

    what is the syntax for a select clause that will only select those records where "ALL" of the values are met?



    with thanks in advance,
    mark

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    More info please.

    Can a manufacturer be in several Categories?

    Usually you would have a construct such as

    Select * from Table
    where
    City ='SomecityName' AND
    BldgProductCategory ='Siding' AND
    someOtherField ='SomeValue"

  3. #3
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    yes, a manufacturer could potentially be in several...
    i had a hunch that I'd have to construct an " and... and... and..." clause

    Code:
    Select * from Table
    where City = 'SomecityName_1' 
                      AND City = 'SomecityName_2' 
                      AND City = 'SomecityName_3' 
                      AND City = 'SomecityName_4' 
                      AND <etc.>
    (guess i was hoping for the discovery of a "learn sometime new every day" function() ... oh well!)
    NTL THNX!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I assume this has another use, as your example could never return a record. That's probably why there's no function for it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    As Paul says that sql won't return any records. When using an AND construct you would typically involve different attributes.

    eg select * from table
    where
    age = 16 AND
    eyecolor = 'green' AND
    haircolor ='brown'


    A person couldn't be age = 16 AND age = 18 AND age = 20

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

Similar Threads

  1. Replies: 2
    Last Post: 12-23-2015, 09:32 PM
  2. Replies: 27
    Last Post: 11-18-2015, 12:39 PM
  3. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  4. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  5. Replies: 4
    Last Post: 08-26-2014, 05:52 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