简体   繁体   中英

MySQL Selecting Results using a wild card Not working

Hi my table data look like this

mysql> SELECT * FROM user_details
    -> ;
+----+----------+------+-----+
| ID | UserName | Type | Age |
+----+----------+------+-----+
|  2 | bandara  |    2 |  26 |
|  3 | panama   |    1 |  12 |
|  4 | sunil    |    2 | 100 |
|  5 | aaa      |    1 |  50 |
+----+----------+------+-----+
4 rows in set (0.00 sec)

iI used a wildcard to select all recods starting from either b or p , but the result set is empty , what i am doing wrong here , please help , thanks in advance.

mysql> SELECT * FROM user_details WHERE UserName LIKE  '[bp]%';
Empty set (0.00 sec)

尝试去掉支架,并为bp搜索标签设置单独的条件。

SELECT * FROM user_details WHERE UserName LIKE  'b%' OR UserName LIKE 'p%';

使用这样的代码,

mysql> SELECT * FROM user_details WHERE (UserName LIKE  'b%') OR (UserName LIKE 'p%');

另一种方法是使用正则表达式

SELECT * FROM user_details WHERE UserName REGEXP '^[bp]';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM