0

I have a string "Hello Help Me, Stackover flow, Google users, Google Plus, ". and in my database table I have

ID    TITLE
--    -----

 1.   Stackover flow
 2.   Google Plus
 3.   Help Me
 4.   Another Title
 5.   Hey World

I need to get IDs 1, 2, 3 using MySQL query, because the string contain those words.

Hows it possible in MySQL

EDIT

select ID, post_title, 
from wp_posts 
where 'Hello Help Me, Stackover flow, Google users, Google Plus,' like concat('%', post_title, '%') and post_type = 'mediawords';

2 Answers 2

2

You want to use like:

select t.id
from table t
where @string like concat('%', title, '%');

This does a string match, so substring can interfere. If you want to take into account the delimiter (', '), then do:

select t.id
from table t
where concat(', ', @string) like concat('%, ', title, '%, ');
Sign up to request clarification or add additional context in comments.

1 Comment

:) thats working :D an additional "," makes the error... Thank you u
1

You can use the in clause:

select id 
from table
where title in ('Hello Help Me', 'Stackover flow', 'Google users', 'Google Plus')

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.