bhat557
bhat557

Reputation: 105

SQL Server LIKE JOIN

I have two tables that I want to join using the "LIKE" function in SQL Server.

Table A has a text field and a bunch of other columns.

Table B has a 2-3 word phrase in the first column and the count of how many times that phrase appears in table A in the second column.

What I want to do is pull in the second column from table B into table A.

So would the following work?:

SELECT A.Text, B.Count, B.Phrase
FROM Table A 
JOIN Table B 
ON LIKE "%B.Phrase%"

Not sure if I would need to CROSS JOIN here or not. Any help would be appreciated.

Upvotes: 0

Views: 50

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270573

I think this is what you want:

SELECT A.Text, B.Count, B.Phrase
FROM Table A JOIN
     Table B 
     ON a.text LIKE '%' + B.Phrase + '%';

Upvotes: 3

Related Questions