Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 保留列值中的前2个字符,删除其余字符_Mysql_Sql - Fatal编程技术网

Mysql 保留列值中的前2个字符,删除其余字符

Mysql 保留列值中的前2个字符,删除其余字符,mysql,sql,Mysql,Sql,我想保留列值的前2个字符,删除mysql表中的其余字符 +----------------+ | id | firstname | +----------------+ | 1 | XYZUUIJ | | 2 | ABCF | +----------------+ 结果: +----------------+ | id | firstname | +----------------+ | 1 | XY | | 2 | AB | +-------

我想保留列值的前2个字符,删除mysql表中的其余字符

+----------------+
| id | firstname |
+----------------+
| 1  | XYZUUIJ   |
| 2  | ABCF      |
+----------------+
结果:

+----------------+
| id | firstname |
+----------------+
| 1  | XY        |
| 2  | AB        |
+----------------+
使用
left()


我认为您不需要删除或更新表,您可以使用
SELECT
语句和
LEFT()

您可以使用
substring()
来执行此操作

UPDATE TABLE1 SET firstname=SUBSTRING(firstname,1,2); 
UPDATE TABLE1 SET firstname=SUBSTRING(firstname,1,2); 
update table set firstname=substr(firstname,1,2)