[英]select where like A% gives no results but %A does php
My table is filled with a total of 40.000 rows with at least over 2.000 rows starting with the letter A
. 我的表总共填充了40.000行,其中至少有2.000行以字母A
开头。
Now my SELECT
query does return some results when I use 现在,当我使用SELECT
查询时,确实会返回一些结果
$selectGames = mysql_query("SELECT * FROM Games WHERE GameName LIKE '%A'");
But when I use : 但是当我使用时:
$selectGames = mysql_query("SELECT * FROM Games WHERE GameName LIKE 'A%'");
a total of 0 rows are being returned. 总共返回0行。 Why is that? 这是为什么?
%A
means "where the end of the string is the letter A". %A
表示“字符串的结尾是字母A”。 A%
is the opposite "a string that STARTS with the letter A" A%
是相反的“以字母A开头的字符串”
%A A%
APPLE N Y
ABBA Y Y
GOUDA Y N
They're totally different matches, so your two queries are NOT equivalent. 它们是完全不同的匹配项,因此您的两个查询不相等。
As well, make sure that your table's collation is set to a case-insensitive match. 同样,请确保将表的排序规则设置为不区分大小写的匹配项。 If it's case-senstive, then a
and A
will be treated differently. 如果区分大小写,则将a
和A
区别对待。
edit: as well, remember whitespace matters: 编辑:同样,请记住空白事项:
mysql> select 'gouda ' like '%a';
^---note the space here
+--------------------+
| 'gouda ' like '%a' |
+--------------------+
| 0 |
+--------------------+
1 row in set (0.00 sec)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.