背景:当查询条件是多个,且某个字段有多个值(或 关系),同时与其他字段又是 与 关系,此时需要注意。
方法:将 或 运算的,用括号括起来。如:查询学生表中,年纪为20岁,且家乡是江苏和浙江的学生信息
//错误代码
select * from student where home='江苏省' or home='浙江省' and age='20';
//正确代码
select * from student where (home='江苏省' or home='浙江省') and age='20';