首页  >  文章  >  后端开发  >  MYSQL AND OR条件问题

MYSQL AND OR条件问题

WBOY
WBOY原创
2016-06-23 13:38:191081浏览


SELECT id,name		FROM test WHERE type_1 = 1 OR type_2 = 1 AND id = 1

这样会印出全部,无视了id=1这个条件,要怎么改才对呢?


回复讨论(解决方案)

SELECT id,name       FROM test WHERE (type_1 = 1 OR type_2 = 1) AND id = 1

SELECT id,name       FROM test WHERE type_1 = 1 OR (type_2 = 1 AND id = 1)

SELECT id,name       FROM test WHERE (type_1 = 1 OR type_2 = 1) AND id = 1

要看你的实际需要

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn