欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

MYSQL AND OR条件问题

程序员文章站 2022-05-08 15:50:01
...
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

要看你的实际需要