How to query the same table for more than one possible results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    How to query the same table for more than one possible results

    Hi,
    I wonder if anyone can tell me how to write this query properly as this one doesnt work.

    where tbl.gallery='Ab stract' and tbl.gallery='Ab stract art'

    Need to query the same table for the results that match the two possible results.

    Thanks in advance
    Richard
  • Jerry Winston
    Recognized Expert New Member
    • Jun 2008
    • 145

    #2
    This is kind of a data questions. I think the syntax you're looking for is OR.

    Code:
    tbl.gallery='Abstract' OR tbl.gallery='Abstract art'

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      alternatively,
      Code:
      tbl.gallery in ('Abstract','Abstract art','Modern art')
      Jared

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        What you have to understand Richard, is that an AND in the WHERE clause is not saying :
        Code:
        Get me :
        All records where {first check}
        AS WELL AS 
        All records where {second check}
        Rather, it is saying :
        Code:
        Get me all records where {first check} AS WELL AS {second check}
        Thus, records are only selected when both checks succeed.

        You need to use the OR conjunction instead as has already been said by Jerry.

        For more flexibility use the IN() function (as per Jared's post). Two checks is fine with OR but going beyond that is better with IN().

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          I'll throw a wrench :)...

          If you're using an OR in any of your condition, place the most probable TRUE condition first. If you're using an AND, place the most probable FALSE condition first.

          This way, a complicated condition need not be test throughout. In OR, only one of the condition needs to be TRUE to make the entire condition as TRUE. In an AND, only one condition needs to be FALSE to make the entire condition as FALSE.

          Although it's not always 100% that the server will parse the condition from left to write, it usually do.

          Happy Coding!!!

          ~~ CK

          Comment

          Working...