Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17566

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)

Upvotes: 0

Views: 172

Answers (3)

Hamed Kamrava
Hamed Kamrava

Reputation: 12847

Another way is to use Regular Expressions :

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

Upvotes: 1

Rajendra Yadav
Rajendra Yadav

Reputation: 635

Use code like this,

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

Upvotes: 1

Sadikhasan
Sadikhasan

Reputation: 18600

Try to remove bracket and put individual condition for b and p search tag like.

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

Upvotes: 1

Related Questions