多输入搜索无法正常工作

时间:2013-11-05 16:42:44

标签: sql

我的问题是,有一个SQL语句并完成工作,但不是我想要的,我希望按行动,类型,城市或房间搜索,只显示人们在查询上选择的内容以及我的代码只搜索所有记录,

SQL代码:

SELECT * 
FROM `inmuebles` 
WHERE 
    action = 'sell' 
    OR type = 'apartment' 
    OR city = 'Los Angeles' 
    AND rooms BETWEEN 2 AND 5

感谢任何帮助

2 个答案:

答案 0 :(得分:0)

SELECT * 
FROM `inmuebles` 
WHERE 
(
  action = 'sell' 
  OR type = 'apartment' 
  OR city = 'Los Angeles' 
)
AND rooms BETWEEN 2 AND 5

答案 1 :(得分:0)

您应该将OR更改为AND,因为现在您的条件太松了。

SELECT * FROM `inmuebles` 
WHERE action = 'sell' 
AND type = 'apartment' 
AND city = 'Los Angeles') 
AND rooms BETWEEN 2 AND 5