Get all matching results from a mysql database

1026 views php
4

I am trying to get the results that matching specific string from a MySQL table column.

For example, if i want to search for the word 'PHP' in my mysql database and there is a row in my mysql table with the string 'I love to code with PHP'. Then I want it to return that whole row.

please show me the way to achieve above result.

answered question

use like "%PHP%"

SELECT * FROM myTable WHERE column LIKE '%PHP%'

1 Answer

4

Short of using full text search, the best you can probably do is to use REGEXP with word boundaries:

SELECT *
FROM yourTable
WHERE col REGEXP '[[:<:]]PHP[[:>:]]';

The reason you want to search with word boundaries here is that you want to match PHP as an isolated word, and not as part of another string.

posted this

Have an answer?

JD

Please login first before posting an answer.