# 记MySQL的一次查询经历

2019/03/14 23:17

SELECT * FROM admins where dep_ids = 24;

SELECT * FROM admins where dep_ids = '24';

MySQL官方文档（章节12.2 Type Conversion in Expression Evaluation）提到：
For comparisons of a string column with a number, MySQL cannot use an index on the column to look up the value quickly. If str_col is an indexed string column, the index cannot be used when performing the lookup in the following statement:

SELECT * FROM tbl_name WHERE str_col=1;

The reason for this is that there are many different strings that may convert to the value 1, such as '1'' 1', or '1a'.

mysql> SELECT 1 > '6x';
-> 0
mysql> SELECT 7 > '6x';
-> 1
mysql> SELECT 0 > 'x6';
-> 0
mysql> SELECT 0 = 'x6';
-> 1

0
0 收藏

0 评论
0 收藏
0