我运行命令select * from victims where fname like '%a%' or address like '%194%';
得到这个
+----+---------+---------+---------+--------+--------------------+--------------------+------+
| id | fname | mname | lname | gender | address | email | card |
+----+---------+---------+---------+--------+--------------------+--------------------+------+
| 1 | Ryan | Anthony | O'Keefe | M | 194 lou Lane | [email protected] | 2543 |
| 3 | Beau | Jacob | Diddly | M | 21 fake cr | [email protected] | 6264 |
| 4 | Anthony | Quinn | Jims | M | 34 lol lane | [email protected] | 3456 |
+----+---------+---------+---------+--------+--------------------+--------------------+------+
对于这个结果,我只想显示数字1,因为这是唯一一个在名字中同时包含a和地址中包含194的。有人能指出我做错了什么吗?
最佳答案
select * from victims where fname like '%a%' or address like '%194%';
应该是
select * from victims where fname like '%a%' AND address like '%194%';
如果你想让名字以
select * from victims where fname like 'a%' AND address like '194%';
关于mysql - 如何使用mysql like子句缩小范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23370693/