1

I have a table like this:

country (id, name)

I want to find the id where for example the search string is "Russian Federation" and in my table is stored the value "Russia".

Pratically the stored value is a substring of the search string.

2 Answers 2

4

You can try it like this:

SELECT *
  FROM Country
  WHERE 'Russian Federation' LIKE CONCAT('%', Name, '%')

Here's the SQL Fiddle Demo.

Sign up to request clarification or add additional context in comments.

Comments

1

If that is the case, then you can do:

select *
from country
where concat(' ', SEARCHSTRING, ' ') like concat('% ', name, ' %')

Or you can use find_in_set():

select *
from country
where find_in_set(name, replace(SEARCHSTRING, ' ', ',')) > 0;

1 Comment

using find_in_set function it seem that doesn't works sqlfiddle.com/#!2/bfb49/13/0

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.