MySQL Forums
Forum List  »  General

compare words of one string that are in another string in different order
Posted by: isaac bs
Date: May 12, 2009 04:57PM

I have the following table, and I want to obtain the IDs of the rows that have column1 with at least 1 word matched in column 2, so the expected result would be only these three from the five

ID 1 - because there are 2 words in common (a2 a3)
ID 3 - two words in common (c1 c2)
ID 4 - one word in common (n2)


CREATE TABLE Words (
id INT PRIMARY KEY,
str1 VARCHAR(50),
str2 VARCHAR(50));

INSERT INTO Words VALUES(1, 'a1 a2 a3', 'a3 a2');
INSERT INTO Words VALUES(2, 'b3 b2 b1', 'x4');
INSERT INTO Words VALUES(3, 'c1 c2', 'c1 c2');
INSERT INTO Words VALUES(4, 'n1 n2', 'n2 y3');
INSERT INTO Words VALUES(5, 'a1 a2 a3', 'a1a2a3');

The order of the words doesnt matter as long as there is at least one word of STR1 in STR2

I'm new to MySQL with other technologies I think this could be solved by using WITH clause

Thanks in Advance

Options: ReplyQuote


Subject
Written By
Posted
compare words of one string that are in another string in different order
May 12, 2009 04:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.