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
  • 168,305
  • 31
  • 280
  • 331
Sebastian
  • 877
  • 1
  • 9
  • 20

2 Answers2

1

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

WHERE @MyString LIKE '%'+[Word]+'%'
Tab Alleman
  • 31,483
  • 7
  • 36
  • 52
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
  • 168,305
  • 31
  • 280
  • 331