我的查询有问题,

SELECT *
FROM requests
WHERE date = '2014/05/18' AND payorTown = 'Malolos'
   OR payeeTown ='Malolos' OR payorTown != 'Malolos' OR payeeTown != 'Malolos'
ORDER BY typeOfAssistance`


我有类似的东西,但是MySQL忽略了第一个条件,即date = '2014/05/18'我非常确定没有记录匹配相同的date。但是结果出在与条件AND payorTown = 'Malolos' OR payeeTown ='Malolos' OR payorTown != 'Malolos' OR payeeTown != 'Malolos'匹配的许多记录中。

关于在WHERE CLAUSE中声明条件是否有任何规则?

最佳答案

您需要整理where条件,而您当前的查询忽略了and条件,例如(where date and payorTown ---> or),您需要通过将所有ors分组(somecond或somecond or)将您和条件与或条件分开。 ..)

SELECT * FROM requests
WHERE date = '2014/05/18' AND
(
(payorTown = 'Malolos' OR payeeTown ='Malolos') OR
(payorTown != 'Malolos' OR payeeTown != 'Malolos')
)
ORDER BY typeOfAssistance

09-20 09:23