What am I doing wrong? OR with AND logic

  • I need help with my where clause. The criteria below works except source_ID '100' keeps showing up in my data.  Basically I have 2 OR's and 1 AND. What is the best way to use these together? Im sure I must be doing this incorrectly.

    FROM table1
    WHERE (APPLE_IND = 1 OR GRAPES_IND = 1)
    AND SOURCE_ID <> 100 OR ADDRESS <> 'NOT APPLICABLE'
  • Maybe this?

    FROM table1
    WHERE (APPLE_IND = 1 OR GRAPES_IND = 1)
    OR (SOURCE_ID <> 100 AND ADDRESS <> 'NOT APPLICABLE')

    If not, can you try putting your requirement into English?

    "Choose rows where either (this) or (this and this) is true"


  • Or maybe you need this?!:

    ...

    AND SOURCE_ID <> 100 AND ADDRESS <> 'NOT APPLICABLE'

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply