0

I have a table with a string column "word" and a rather large text. Now I want to find those words that appear within that text. So IMHO I need a reverse LIKE operator. Ist that possible in plain SQL (no stored procedures)?

Example: Finding words in rhymes

| ID | Word |
| 1  | star |
| 2  | moon |
| 3  | sun  |
| 4  | sky  |

Text: Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky.

==> should find ID 1: start, 4: sky

3
  • duplicates Find strings in text but that question has no SQL answer Commented Apr 22, 2015 at 19:44
  • 1
    You can reverse the LIKE operator: WHERE @MyString LIKE '%'+[Word]+'%' Commented Apr 22, 2015 at 19:45
  • should be SQL agnostic (in fact I am using Java, querydsl, jpa and currently mysql, which might change later) Commented Apr 22, 2015 at 19:46

2 Answers 2

1

Try like this:

select ID from tablename
where 'Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky.'
LIKE CONCAT('%', word, '%');

SQL FIDDLE DEMO

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

Comments

1

The LIKE operator IS reversible. This is all you need to do:

WHERE @MyString LIKE '%'+[Word]+'%'

2 Comments

Your syntax is not MySQL-compliant.
Ok, I don't know MySQL syntax, but would the principle work in MySQL?

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.