最佳答案
I am having trouble with a mysql query. I want to exclude values of 2. So I thought I would do following:
table products
id | name | backorder
-------------------
1 | product1 | NULL
2 | product2 | NULL
3 | product3 | 2
SELECT name from `products` p
WHERE backorder <> '2'
但是,这并没有给出Product1,Product2的预期结果,而是给出了一个空的结果表。
On the other hand if I use
SELECT name from `products` p
WHERE backorder = '2'
Then it produces: product3
. But I want to get those records where it is not equal to 2
.
Something is not working with the <> '2'
. Could it be that the NULL
values are throwing it off? Can anyone suggest a fix.
Thanks in advance!