早教吧 育儿知识 作业答案 考试题库 百科 知识分享

mysql匹配问题,使用like2次匹配结果不一样,求解.ql>select*fromoswherebooknamelike"Linux%"oramount=50;+----+-----------------+--------+------------+-------+--------+|id|bookname|writer|bookdate|price|amount

题目详情
mysql匹配问题,使用like2次匹配结果不一样,求解. ql> select * from os where bookname like "Linux%" or amount=50;
+----+-----------------+--------+------------+-------+--------+
| id | bookname | writer | bookdate | price | amount |
+----+-----------------+--------+------------+-------+--------+
| 1 | Live with Linux | Tube | 2007-01-25 | 75 | 50 |
| 2 | Linux inside | Kevin | 2008-02-15 | 83 | 50 |
| 3 | L.A.M.P | Tom | 2008-02-05 | 82.5 | 50 |
+----+-----------------+--------+------------+-------+--------+
3 rows in set (0.00 sec)
mysql> select * from os where bookname like "Linux%" and amount=50;
+----+--------------+--------+------------+-------+--------+
| id | bookname | writer | bookdate | price | amount |
+----+--------------+--------+------------+-------+--------+
| 2 | Linux inside | Kevin | 2008-02-15 | 83 | 50 |
+----+--------------+--------+------------+-------+--------+
1 row in set (0.00 sec)
为什么上一句能够匹配到id=1的行,第二句就不行了呢?
and or还有什么不可告人的秘密?
▼优质解答
答案和解析
and 是两个条件都要符合, or是只要满足一个条件就行.