SELECT默认情况下不区分大小写。对于区分大小写的实现,使用BINARY运算符。以下是语法:select *from yourTableName where BINARY yourColumnName=yourValue;
让我们首先创建一个表-mysql> create table DemoTable
(
Name varchar(40)
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values('Chris');
mysql> insert into DemoTable values('CHRIS');
mysql> insert into DemoTable values('chris');
mysql> insert into DemoTable values('CHris');
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+-------+
| Name |
+-------+
| Chris |
| CHRIS |
| chris |
| CHris |
+-------+
4 rows in set (0.00 sec)
以下是区分大小写的选择查询-mysql> select *from DemoTable where BINARY Name='Chris';
这将产生以下输出-+-------+
| Name |
+-------+
| Chris |
+-------+
1 row in set (0.04 sec)