SELECT COLUMN 和 COUNT 中区分大小写,mysql?
好吧,我在这里有点困惑。在我的数据库中,我有 5 行此数据 => “[email protected]"(全部小写),这是我的代码,查询1(我使用php和mysql):
$str = '[email protected]';
$sel = mysql_query("SELECT COUNT(*)
FROM table
WHERE `column` = '{$str}'");
$num = mysql_num_rows($sel);
echo $num;
结果是1。但是如果我更改为Query2,
SELECT column
FROM table
WHERE `column` = '{$str}'"
它返回5。
另一个问题是,如果我想找出存在的行数,我应该使用哪个查询数据库,查询1或2,就查询速度而言?
Okay, I am abit confusing here. In my database I have 5 rows of this data => "[email protected]" (all lower case), and This is my code, Query 1 (I am using php and mysql):
$str = '[email protected]';
$sel = mysql_query("SELECT COUNT(*)
FROM table
WHERE `column` = '{$str}'");
$num = mysql_num_rows($sel);
echo $num;
The result is 1. But if I change to Query2
SELECT column
FROM table
WHERE `column` = '{$str}'"
It returns 5.
And another question is, which query should I use if i want to find out the number of rows exist in database, query 1 or 2, in term of query speed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将返回从查询中选择的行数。对于查询一,由于您从表中选择
COUNT(*)
,因此它会返回一行,其中包含一个单元格:该单元格的值为 5。第二个查询选择具有该值的所有条目来自$str
,因此mysql_num_rows($sel);
确实会返回 5。至于另一个问题,首先查询是否更有效,但是如果您正在寻找值为
$str
的行数,不要使用mysql_num_rows()
,而是mysql_fetch_row()。This returns the number of rows selected from your query. For query one, since you select
COUNT(*)
from your table, it returns one single row with one cell into it: value of this cell is 5. The second query select all entries that have the value from$str
, somysql_num_rows($sel);
will indeed return 5.As for the other question, first query if more efficient, but if you're looking for the number of rows with value
$str
, do not usemysql_num_rows()
but mysql_fetch_row().