I am having difficulty I writing a correct sqlite query to achieve the following.
I have 2 tables: words and sounds
example: content table words:
**wordName**
ape
base
house
step
round
hat
hoot
hot
content table sounds:
**soundName** **soundActive**
a 1
b 0
o 1
ou 0
u 1
s 1
h 1
t 1
e 0
f 0
p 1
I would like to write a query that gives me back words that only contain active sounds. Notice ou
is not the same as o
with u
.
So in this case the result should be: hat
I came up with the following:
select words.wordName
from words join sounds on words.wordName like '%'||sounds.soundName||'%'
where sounds.soundActive=1
group by words.wordName;
But this gives me also words that have sounds that are not active. As soon as it has one active sound the word is given.
I tried with words.wordName not like '%'||sounds.soundName||'%' where sounds.soundActive=0 group by words.wordName
what seemed more logical to me but this gives back all words.
Update: Yohanes Khosiawan second solution works on sqlite.
select words.wordName as wName, avg(sounds.soundActive) as allActive
from words join sounds on words.wordName like '%'||sounds.soundName||'%'
group by words.wordName
having allActive=1;
But to also get the sounds with one/two letters work I will make a new table: example: content table sounds2:
**sound2Name** **sound2Active**
au 0
ou 1
oo 0
The result should be house
, hat
, hot