2

Here is what I was want to Optimize this query

SELECT * 
FROM users 
where `username` like "%abc%" 
   or `name`     like "%abc%" 
   or `email`    like "%abc%"

This search get result from users where any of username , name , email like %abc%

So I tried to use in with like But

I was looking for mysql Like in and I have found this answer stackoverflow :Mysql like in

So the solution was regex

But I want to make the regex not use OR

I want to be like this

SELECT * from users where abc REGEXP 'username|name|email';

So the answer

1 Answer 1

1

Do you mean something like this? >>

SELECT * from users where CONCAT(username, ',', name, ',', email) REGEXP 'abc'
Sign up to request clarification or add additional context in comments.

2 Comments

Your query is very good for me , and the same result work with LIKE statment Is there any diffrent between regex and like with your query
@MonaAbdelmajeed - Your question asks for regex solution, so I used REGEXP in the example. In this case, you will get same results if you use like or REGEXP. However for more complex search/match patterns REGEXP is better choice...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.