Home  >  Article  >  Backend Development  >  MYSQL AND OR条件问题

MYSQL AND OR条件问题

WBOY
WBOYOriginal
2016-06-23 13:38:191081browse


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

要看你的实际需要

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn