试试这个查询
select mid('test hello world',locate(' ','test hello world'),length('test hello world'))
locate : 定位文本中的第一个空格
length : 获取文本的长度
mid :选择第一个值(这将是空格后的第一个字母)到第二个值(这将是最后一个字母)之间的单词
所以现在更新查询可以像
update a set a=mid(a,locate(' ',a),length(a)) from ...
这是一个测试代码
create table stackoverflow (test varchar(50));
insert into stackoverflow values('a b c');
insert into stackoverflow values('d e f');
insert into stackoverflow values('g h i');
SELECT * FROM `stackoverflow`;
update stackoverflow set test=mid(test,locate(' ',test),length(test));
SELECT * FROM `stackoverflow`;
这里是结果
mysql> create table stackoverflow (test varchar(50));
Query OK, 0 rows affected (0.44 sec)
mysql> insert into stackoverflow values('a b c');
Query OK, 1 row affected (0.03 sec)
mysql> insert into stackoverflow values('d e f');
Query OK, 1 row affected (0.07 sec)
mysql> insert into stackoverflow values('g h i');
Query OK, 1 row affected (0.15 sec)
mysql> SELECT * FROM `stackoverflow`;
+-------+
| test |
+-------+
| a b c |
| d e f |
| g h i |
+-------+
3 rows in set (0.00 sec)
mysql> update stackoverflow set test=mid(test,locate(' ',test),length(test));
Query OK, 3 rows affected (0.11 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> SELECT * FROM `stackoverflow`;
+------+
| test |
+------+
| b c |
| e f |
| h i |
+------+
3 rows in set (0.00 sec)