Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite, select where field 'like' field from another table

Tags:

sqlite

I'm trying to remove "bad words" from a table using a list of offensive words from another table, but the offensive words are often in lemma form. Thus, I can't always do a exact match. I need to use a LIKE quantifier, for example WHERE text LIKE '%badword%'

Is there a way for me to try to select all the rows that contains a word from another table, but by specifically using the LIKE clause.

I'll give an example of what I was trying to do. This didn't work, but should give you an idea of what I'm trying to do:

SELECT *
FROM entry 
WHERE headword LIKE IN
( SELECT word
FROM sies )

Now I know that the LIKE doesn't fit into this query, but I'm trying to get something to this effect working.

EDIT: This is the latest thing I tried, that did not work:

SELECT s.*
FROM sies AS s, entry AS e 
WHERE e.headword LIKE ('%' + s.word + '%')
like image 366
amateurjustin Avatar asked Mar 17 '23 08:03

amateurjustin


1 Answers

You can try the following query:

select s.* from sies s, entry e where s.words like '%' || e.word || '%'

Here I have assumed that, sies is your regular table and entry is the table with the dirty words.

You can check the Demo here.

like image 55
Prerak Sola Avatar answered May 09 '23 06:05

Prerak Sola