Mysql – How to match string in varchar field from one table with other table

MySQL

I have two tables,

table1 having a single column:

id     |   sentence(varchar 255)
1      |   I am a boy; a good boy.

and table2 having two columns:

word    |   meaning
I       |     مين
am      |     هون
a       |     أيك 
boy     |     لرقة 
good    |     اشا 

Now I want to query both tables in such a way that I will get each word with its translation.

For the sample data the query result must be:

sentence                  |    word_meaning (virtual column)
I am a boy; a good boy.   |  {"I":"مين", "am":"هون", "a":"أيك", "boy":"لرقة", "good":"اشا"}

As you can see in word_meaning column, each word has its meaning with json.

Best Answer

What client language are you using? That is where you need to split a sentence into "words" and where you will need to put the output back together after fetching the individual meanings. Do not try to do it in SQL.

Related Question