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

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319
Sebastian
  • 827
  • 1
  • 8
  • 19

2 Answers2

1

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

WHERE @MyString LIKE '%'+[Word]+'%'
Tab Alleman
  • 30,929
  • 7
  • 33
  • 51
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

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319