user6617474 user6617474 - 3 months ago 7
MySQL Question

search the inbetween string using sql query

In

wp_postmeta
table
meta_value
contains the value
http/google.co.in/


If the user searches for
http/google.co.in/testing
, then the resultset should contain
http/google.co.in/


I tried with following query:

SELECT * FROM wp_postmeta WHERE meta_value LIKE '%http/google.co.in/testing%'


but it did not return the expected result.

How can i get the desired result? How can I use regular expressions to get this result?

Answer

if you use sql: .....LIKE '%http/google.co.in/testing%', then DB will look for any string containing "http/google.co.in/testing". Note that your desired result does not contain "testing" inside.

Let's try:

SELECT * FROM wp_postmeta WHERE meta_value LIKE CONCAT('%', SUBSTR('http/google.co.in/testing', 1, 18), '%')
Comments