AND和OR
在我们查询的过程中有时候不仅仅只有一个调整 那么上述的条件都可以通过AND或者OR组合起来,如:
SELECT * FROM 表 WHERE NAME LIKE '%内容%' AND ID BETWEEN 1 AND 10
解析:AND 是且的意思 代表此查询既要满足NAME LIKE '%内容%' 又要满足ID BETWEEN 1 AND 10
SELECT * FROM 表 WHERE NAME LIKE '%内容%' OR ID BETWEEN 1 AND 10
解析:OR是或的意思 代表此查询只要满足NAME LIKE '%内容%' 或者ID BETWEEN 1 AND 10 其中一个就行
SELECT * FROM 表 WHERE (NAME LIKE '%内容%' OR NAME LIKE '%123%' ) AND ID BETWEEN 1 AND 10
解析:AND 和OR也可以搭配使用,此语句代表除了满足了ID BETWEEN 1 AND 10 还要满足 NAME LIKE '%内容%' 和 NAME LIKE '%123%' 其中一个