Reputation: 37
SELECT UT_10, LT_10, ACT_10, LT_10 - ACT_10, UT_10 - ACT_10
FROM distributor
WHERE (
LT_10 - ACT_10 <>1
OR LT_10 - ACT_10 <>2
)
AND ACT_10 <>10
AND
(
UT_10 - ACT_10 =1
OR UT_10 - ACT_10 =2
)
AND ACT_10 <>10
I wrote this query in mysql. I don’t want 1 or 2 result but 1 is display in result please help me. or condition is not working with mysql query.
you can see here result: CLICK HERE FOR LARGE IMAGE
Upvotes: 3
Views: 347
Reputation: 4830
Replace
LT_10 - ACT_10 <>1
OR LT_10 - ACT_10 <>2
With
LT_10 - ACT_10 NOT IN (1,2)
Results where LT_10 - ACT_10
equals 1
are returned by your original query because you used OR
, if you only wanted results where it is not equal to either you should have used AND
. This can be shortened using NOT IN
as shown in my example above.
Your original condition serves no purpose as LT_10 - ACT_10
can only take one value - it will never be equal to 1
and 2
(which is what would be needed for both parts of the original OR
condition to evaluate to false
)
Upvotes: 6