mySQL查询或不是

时间:2013-11-15 21:27:16

标签: mysql

我有这个查询

Select ID, title,tags from items where ID != 305096 AND title LIKE '%airplane%' or title LIKE '%car%' ORDER BY ID DESC LIMIT 20

除了ID == 305096之外,我想获得所有结果。我还尝试使用'<>'但都没有用。 你有什么主意吗?谢谢!

3 个答案:

答案 0 :(得分:3)

Select ID, title,tags from items where ID != 305096 AND (title LIKE '%airplane%' or title LIKE '%car%') ORDER BY ID DESC LIMIT 20

答案 1 :(得分:1)

必须与括号分组:

Select ID, title,tags from items where ID != 305096 AND (title LIKE '%airplane%' or title LIKE '%car%') ORDER BY ID DESC LIMIT 20

答案 2 :(得分:0)

尝试围绕你的逻辑做一些事情:

Select ID, title,tags from items 
where (ID != 305096) AND (title LIKE '%airplane%' or title LIKE '%car%') 
ORDER BY ID DESC LIMIT 20