Amuk Saxena
Amuk Saxena

Reputation: 1571

Match some words between two columns

I need to match some words between two columns. I am not able to find this solution anywhere, so i need help.

|==========title=================|======title================|
|...Toscano Brioche..............|...Toscano .... ...........|
|....Toscano Brioche Creme.......|...Brioche Creme Butter....|

OUTPUT==>

|==========title=================|======title================|===OUTPUT===|
|...Toscano Brioche..............|...Toscano .... ...........|   1        |
|....Toscano Brioche Creme.......|...Brioche Creme Butter....|   1        |
|....Strawberry CAKE Bakery......|...Brioche Creme Butter....|   0        |

How to compare these two columns named 'title' in table, I need to match some words between the two columns. For example, in row 1, 'Toscano' is common in both columns, in row 2, 'Brioche Creme' is common.

Upvotes: 1

Views: 3178

Answers (2)

Adarsh Rajput
Adarsh Rajput

Reputation: 1276

Not able to understand your question completely, I think you want to compare 2 columns, if those have some common words then show 1. May be it can help you..

select title1,title2,title1 like concat("%",replace(title2," ","%"),"%") as matched from table_name

EDIT: You can see accepted answer if these two columns are from different table. By the way that is obvious. But don't forgot to use replace as I did if you want to find all words anywhere.

Upvotes: 2

lpg
lpg

Reputation: 4937

Maybe something like this (SQL FIDDLE here) ?

SELECT table1.title title1, table2.title title2
FROM table1, table2
WHERE table1.title LIKE CONCAT('%',table2.title,'%') 
OR table2.title LIKE CONCAT('%',table1.title,'%');

Upvotes: 2

Related Questions