Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Mysql: Compare two columns word and print total common words count

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 650
    Comment on it

    I am posting this blog because I was facing issue to show the total common counts in 3rd column from two columns. This is following table which contain these records:

    |==========title=================|======title================|
    |...Cat Dog......................|...Cat.... .... ...........|
    |....Titanic Bag Cream...........|...Bag Titanic Butter......|
    |....Apple Banana Mangoe.........|...Tomatoe Tree. Butter....|
    

     

    I need to get the following output:

     

    |==========title=================|======title================|===OUTPUT===|
    |...Cat Dog......................|...Cat.... .... ...........|   1        |
    |....Titanic Bag Cream...........|...Bag Titanic Butter......|   2        |
    |....Apple Banana Mangoe.........|...Tomatoe Tree. Butter....|   0        |

     

    Solution was very simple, just write this query to get the output:

     

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

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: