I need a SQL query to get the common words only between two sentences. For example:
Sentence 1: This site is very helpful
Sentence 2: I need a helpful site
The result should be: site helpful
Also, if I need to compare sentence 1 to table field records to get the record that contains most common words to sentence 1, what can I do?
You question title says MSQL, so I’m taking your question as a Sql Server question.
Depending on SQL Server version/Server Configuration, you’ll need a split function that can split a string on a delimiter of choice. Here’s such a function.
SELECT sentence1.data
FROM dbo.fnSplit('This site is very helpful',' ') sentence1
INNER JOIN dbo.fnSplit('I need a helpful site',' ') sentence2 ON sentence1.data = sentence2.data