user2268244
user2268244

Reputation: 463

MySQL - Select rows with multiple occurrence of LIKE within a field

Let's say I have this table:

id    post_content

  1. Lorem ipsum Mike dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.
  2. Lorem ipsum Mike dolor sit amet, consectetur adipiscing Mike elit, sed do eiusmod tempor incididunt ut labore.
  3. Lorem ipsum Mike dolor sit amet, consectetur adipiscing Mike elit, sed do eiusmod tempor incididunt ut labore Mike.

How can I construct a SELECT ..... post_content LIKE %Mike% query that will only return rows with multiple occurrences of Mike? In this case, record 2 and 3.

Thank you.

Upvotes: 1

Views: 1446

Answers (2)

Talha Abrar
Talha Abrar

Reputation: 882

You can simply do this,

SELECT * FROM `table_name` WHERE post_content LIKE '%mike%mike%'

i tested it out in MySQL, and it is working exactly as you want it to.

enter image description here

Upvotes: 1

Zoran Horvat
Zoran Horvat

Reputation: 11301

Maybe if you tried:

SELECT * FROM ... WHERE post_content LIKE '%Mike%Mike%'

This is tricky and I don't have MySQL right now to try it. I know from past experience that Oracle and MS SQL worked differently with that same approach, so you'll have to try it.

Upvotes: 3

Related Questions