0

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?

1
  • 1
    Usually, "http" is followed by a colon. Could that be your problem? Commented Aug 9, 2016 at 11:32

3 Answers 3

1

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), '%')
Sign up to request clarification or add additional context in comments.

4 Comments

@user6617474 : please try
@user6617474 : beware that for http/google.co.in/, sometimes it may just exists as http/google.co.in without trailing /
@user6617474 : if you don't mind, could you please mark as answer?
if this is answer for your then question. then tick as a answer @user6617474
1

this '%http/google.co.in/testing%' means you are looking for any string that contains 'http/google.co.in/testing' so 'http/google.co.in/' won't return any result because it doesn't contain the string you are looking for. You can use SUBSTR() to search for a part your string.

Comments

0

As others have pointed out, LIKE searches for strings containing the entire search string (plus any other strings where the %s are), not strings containing a substring of your string. I don't know if there is such a command. You suggested perhaps regex is your answer. MySQL does in fact have a regex command, which a quick Google search would show you the documentation for here: http://dev.mysql.com/doc/refman/5.7/en/regexp.html Do you need further help determining your regex, or is this enough? If you want further help, you'll have to clarify exactly what regex would be searching for, because you'd have to understand the components of your search string to know what will be constant and what will be variable.

Comments

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.