User420
User420

Reputation: 137

SQL OR statement in Wildcard

My current MySql wild card is LIKE '%A%B%'. This can return values that contain A and B.

Can anyone suggest how can I alter the wildcard statement to return values that contain either A or B.

Thanks in advance.

Upvotes: 2

Views: 1747

Answers (2)

e4c5
e4c5

Reputation: 53734

You can use REGEXP

 select * from Table1 where some_column REGEXP '[AB]'

there are lots of different ways in writing this as a regular expression, the above basically means containing A or B.

Generally you want to avoid using REGEXP and LIKE '%something' because the do not use indexes. Thus for large tables these operations would be unusable. When you want to do a search of this kind it's always best to stop and ask: "Have I got the best database design?", "Can I use full text search instead?"

Upvotes: 2

HEEN
HEEN

Reputation: 4721

You can add as many like operator you want within the parenthesis with OR condition like below

select * from tablename where (column_name  like '%test%' or same_column_name  like '%test1%' or 
            same_column_name  like '%test2%' or same_column_name  like '%test3%')

For more info have a look at the below link.

SQL Server using wildcard within IN

Hope that helps you

Upvotes: 2

Related Questions