Search code examples
mysqlregexsql-like

MYSQL Like Improper results


I am using Like to find something pattern from table

sample table:

id | title |
=============
 1 | f550  |
-------------
 2 | f550  |
-------------
 3 | f-550 |
-------------
 4 | f 550 |

I am using LIke query to check my receords, so lets say if I search for f550 it is bringing only 2 records that is correct technically but I want all records having any pattern such as (f550,f-550,f 550)

Is there any way besides REGEX I can do?

My query fires like this

SELECT * FROM `qd_posts` WHERE title LIKE  '%f550%';

I tried using different combinations such like this but didn't worked.

SELECT * FROM `qd_posts` WHERE title LIKE  '%f%-%550%';

I have even tried using RLIKE but still not got the result


Solution

  • You could try using '%f%550%'

    SELECT * 
    FROM `qd_posts` 
    WHERE title LIKE  '%f%550%';
    

    or

    SELECT * 
    FROM `qd_posts` 
    WHERE title LIKE  'f%' AND LIKE '%550';