Home > Enterprise >  SQL : how to check if a column value has all elements from a string array
SQL : how to check if a column value has all elements from a string array

Time:09-19

I have a table where a column called Phrase has a sentence.

For example :

ID  |     Phrase    |
---- --------------- 
 1  | I can do it   |
 2  | Where is that |

I also have another table which has keywords. For example :

select keyword 
from keywords 

returns

    ID | Keywords |
    --- ---------- 
     1 |    I     |
     2 |    can   |
     3 |    do    |
     4 |    it    |

How can I can check if the phrase column for a given row has all matching keywords. Something like:

select * 
from table 
where phrase like '%I%' 
  and phrase like '%do%' 
  and phrase like '           
  •  Tags:  
  • sql
  • Related