'Is there a faster way of using NOT LIKE for a long list of search terms instead of {AND "Column" NOT LIKE '%word1%'} etc, in an SQL Query?
So I'm trying to exclude a bunch of different entries with specific words from my query and I was wondering if there was a more efficient/faster way of doing this over the method that I am currently using:
AND LOWER("Column") NOT LIKE LOWER('%word1%')
AND LOWER("Column") NOT LIKE LOWER('%word2%')
AND LOWER("Column") NOT LIKE LOWER('%word3%')
AND LOWER("Column") NOT LIKE LOWER('%word4%')
AND etc....
This works but it gets overly long and complex very quickly. I've tried a few other methods that I found from searching but none of them fit my use case.
I need the wild cards included because the rest of the entry changes between each record and the LOWER(...)
is needed to make the query case in-sensitive as some entries are capitalised and some aren't.
Let me know if any more info is needed or you have suggestions about anything else I can change to make it better in general.
Here is the full SQL statement if the context helps:
SELECT "Description", "Debit Amount", "Balance", "Categories"
FROM "Transactions"
WHERE "Debit Amount" IS NOT NULL
AND LOWER("Description") NOT LIKE LOWER('%word1%')
AND LOWER("Description") NOT LIKE LOWER('%word2%')
AND LOWER("Description") NOT LIKE LOWER('%word3%')
AND LOWER("Description") NOT LIKE LOWER('%word4%')
AND etc....
ORDER BY 2 DESC
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|