Results 1 to 7 of 7
  1. #1
    won_lek is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    3

    WHERE IN with AND is not working. What's wrong with this?

    I have attached a picture with this post. Anybody has idea why SQL Query statement is not working?

    WHERE IN ((xxxxxx = 10 AND yyyyyy= 20),(xxxxx=3 AND yyyyy=5))

    Why the above SQL statement can't correctly return what I want?



    (Please refer to the picture that I have uploaded?)

    Thanks.

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    I think in the example you need a statement like:

    select MachineID, MachinePart, MachineColour from Table1 where (MachineColour = "Yellow" and Machinepart = "Cover) or (Machinecolour = "Yellow" and machinePart = "Shaft")

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Or, using IN() properly:

    ...where MachineColour = "Yellow" and Machinepart IN("Cover", "Shaft")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    won_lek is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    3

    Smile Sorry, I can't :-)

    I can't changed to what you have suggested me.

    This is because I don't know how many of the combination will appear. I will use the listbox in the future.

    And actually it is not only Yellow colour as mentioned in the example.
    There will be various combination.

    Sorry about that, and really thanks and hope someone can help me.

  5. #5
    won_lek is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    3
    Anybody has any idea on this? please?

  6. #6
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    of course you don't have to copy the statements, they're just examples of the correct syntaxis you can use. You can have indefinite combinations, just respect the correct syntax and the query will work.

    succes
    NG

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I love moving targets. Here's one way to use a multiselect listbox:

    http://www.baldyweb.com/multiselect.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. What's wrong with this query?
    By jsoldi in forum Queries
    Replies: 2
    Last Post: 10-11-2010, 07:45 AM
  2. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM
  3. What's wrong with this expression
    By tallroger in forum Access
    Replies: 1
    Last Post: 05-05-2009, 04:00 PM
  4. Compiler WRONG example-DB
    By pacala_ba in forum Access
    Replies: 12
    Last Post: 04-18-2009, 01:00 PM
  5. What am I doing wrong?
    By brandon in forum Access
    Replies: 2
    Last Post: 08-03-2008, 10:26 AM

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