MySQL – How to Get Rows Containing Only Certain Strings

MySQL

I have these words in my words table in a MySQL db:

kaki

koku

kao

kakeru

How can I get all rows that contains ONLY 'ka','ki','ku','ke','ko'?

I want to get kaki and koku but not kao and kakeru, because although kao contains ka, it also has o, and although kakeru contains ka and ke it also contains ru.

I have tried:

select *
from words
where (
    word like '%ka%'
    or word like '%ki%'
    or word like '%ku%'
    or word like '%ke%'
    or word like '%ko%'
    );

but I don't get the result that I want.

EDIT: I can't comment, but yes I want to break it into 2 syllables.

Best Answer

Try some REPLACE() tricks:

SELECT *
FROM #words
WHERE REPLACE(
    REPLACE(
    REPLACE(
    REPLACE(
    REPLACE(
    word
    ,'ka','')
    ,'ke','')
    ,'ki','')
    ,'ko','')
    ,'ku','')
    = '';