I’m going to take a stab at this despite there being incomplete information in your post.
A chain of just AND
operators will require every expression to evaluate true for every row returned. This is as fundamental as gravity.
In short, AND
works, it just doesn’t work as you expect it to.
What is likely going on here is you have other expressions in your query that you don’t feel are relevant to the question.
For example
SELECT Column1,
Column2,
Column3
FROM myTable
WHERE Column1 = 'abc'
AND Column2 = 123
AND column3 = 'zyx'
OR Column3 = 'xyz'
Is logically completely different from:
SELECT Column1,
Column2,
Column3
FROM myTable
WHERE Column1 = 'abc'
AND Column2 = 123
AND (column3 = 'zyx'
OR Column3 = 'xyz')
In the first example the generally accepted order of operations would evaluate your query as
(Column1 = 'ABC AND Column2 = 123 AND column3 = 'zyx')
Meaning all of the above must be true
OR Column3 = 'xyz'
In case 1, any row with column3 equal to ‘xyz’ will be returned regardless of whether the AND
operations evaluate as true. You’re saying give me a row if EITHER the and operations or the OR operation are true.
If you want SQL to evaluate your expression differently, you need to specify priority using parenthesis as in case 2.
For more information, take a look at msdn operator precedence you’ll see that ANDs are evaluated long before ORs.
Also, if you post your actual query we can be more specific in our help as to where exactly the problem is.
solved Operator AND is not function property [closed]