简体   繁体   中英

Exclude results if all this words are matched from SQlite3 query in PHP

I want to do a SQLITE3 QUERY that allows to me to exclude results that matches a specific amount of words. For example.

SELECT * FROM TABLE WHERE TEXT NOT LIKE ("ONE","TWO", "THREE");

I want to exclude results only if all this words are matches. But if only "ONE" and "TWO" are matched, then do not exclude that. Also, if only one word is matched, do not exclude.

I would prefer to do it with the LIKE statement

We can try using INSTR as follows:

SELECT *
FROM yourTable
WHERE
    INSTR(text, 'ONE') = 0 OR
    INSTR(text, 'TWO') = 0 OR
    INSTR(text, 'THREE') = 0;

This logic returns a record if any one of ONE , TWO , or THREE be missing in the text.

Here is the case insensitive version:

SELECT *
FROM yourTable
WHERE
    INSTR(UPPER(text), 'ONE') = 0 OR
    INSTR(UPPER(text), 'TWO') = 0 OR
    INSTR(UPPER(text), 'THREE') = 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM