为什么此sql无法执行?
SELECT * FROM TEST_190530 WHERE ID=1A;
我知道1A需要用引号引起来,因为它是一个字符串,例如“ WHERE ID ='1A';”。 但是我想知道原因。为什么 1A 不带引号在sql中被标识为列名?
CREATE TABLE TEST_190530
(ID VARCHAR(50));
INSERT INTO TEST_190530 VALUES('1A');
INSERT INTO TEST_190530 VALUES('1');
INSERT INTO TEST_190530 VALUES('2C');
mysql> SELECT * FROM TEST_190530 WHERE ID=1;
+----+
| ID |
+----+
| 1A |
| 1 |
+----+
2 rows in set
mysql> SHOW WARNINGS;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '1A' |
| Warning | 1292 | Truncated incorrect DOUBLE value: '2C' |
+---------+------+----------------------------------------+
2 rows in set
mysql> SELECT * FROM TEST_190530 WHERE ID=1A;
1054 - Unknown column '1A' in 'where clause'
mysql> SHOW WARNINGS;
+-------+------+---------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------+
| Error | 1054 | Unknown column '1A' in 'where clause' |
+-------+------+---------------------------------------+
1 row in set