MySQL Query返回包含空格的行

时间:2022-06-01 18:47:04

I would like to run a query on a MySQL database table to return all the rows where the column data has white space. e.g.:

我想在MySQL数据库表上运行查询以返回列数据具有空格的所有行。例如。:

Usernames
andy davies
peter
geoff smith
steve
bob paul

用户名andy davies peter geoff smith steve bob paul

The query would only return 'andy davies', 'geoff smith', 'bob paul' and ignore 'peter' and 'steve'

查询只会返回'andy davies','geoff smith','bob paul'并忽略'peter'和'steve'

Any ideas?

有任何想法吗?

3 个解决方案

#1


34  

SELECT ...
   ...
  WHERE username LIKE '% %'

#2


4  

INSTR() returns the position of the specified substring in the given string. Use it in the WHERE conditional.

INSTR()返回给定字符串中指定子字符串的位置。在WHERE条件中使用它。

SELECT * FROM table WHERE INSTR(`username`, ' ') > 0

#3


1  

An idea:

一个主意:

SELECT names FROM tbl_name WHERE names LIKE "% %";

#1


34  

SELECT ...
   ...
  WHERE username LIKE '% %'

#2


4  

INSTR() returns the position of the specified substring in the given string. Use it in the WHERE conditional.

INSTR()返回给定字符串中指定子字符串的位置。在WHERE条件中使用它。

SELECT * FROM table WHERE INSTR(`username`, ' ') > 0

#3


1  

An idea:

一个主意:

SELECT names FROM tbl_name WHERE names LIKE "% %";