sql语句的优先级or and的疑问
mysql>select*fromfruits->wheref_name='apple'->andf_price>5->ands_idin('101','102');+-...
mysql> select * from fruits
-> where f_name='apple'
-> and f_price>5
-> and s_id in ('101','102');
+------+------+--------+---------+---------+
| f_id | s_id | f_name | f_price | f_email |
+------+------+--------+---------+---------+
| a1 | 101 | apple | 5.20 | NULL |
+------+------+--------+---------+---------+
1 row in set (0.00 sec)
mysql> select * from fruits
-> where f_name='apple'
-> and f_price>5
-> and s_id=101 or s_id=102;
+------+------+------------+---------+---------+
| f_id | s_id | f_name | f_price | f_email |
+------+------+------------+---------+---------+
| a1 | 101 | apple | 5.20 | NULL |
| b1 | 102 | blackberry | 10.20 | NULL |
| bs1 | 102 | orange | 11.20 | NULL |
| t1 | 102 | banana | 10.30 | NULL |
| t2 | 102 | grape | 5.30 | NULL |
+------+------+------------+---------+---------+
5 rows in set (0.00 sec)
我觉得这两条语句的执行结果 应该一样啊。都应该只返回一条,为什么不一样。 展开
-> where f_name='apple'
-> and f_price>5
-> and s_id in ('101','102');
+------+------+--------+---------+---------+
| f_id | s_id | f_name | f_price | f_email |
+------+------+--------+---------+---------+
| a1 | 101 | apple | 5.20 | NULL |
+------+------+--------+---------+---------+
1 row in set (0.00 sec)
mysql> select * from fruits
-> where f_name='apple'
-> and f_price>5
-> and s_id=101 or s_id=102;
+------+------+------------+---------+---------+
| f_id | s_id | f_name | f_price | f_email |
+------+------+------------+---------+---------+
| a1 | 101 | apple | 5.20 | NULL |
| b1 | 102 | blackberry | 10.20 | NULL |
| bs1 | 102 | orange | 11.20 | NULL |
| t1 | 102 | banana | 10.30 | NULL |
| t2 | 102 | grape | 5.30 | NULL |
+------+------+------------+---------+---------+
5 rows in set (0.00 sec)
我觉得这两条语句的执行结果 应该一样啊。都应该只返回一条,为什么不一样。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询