Trying to use this sql statement. The first 2 parts work fine, I am trying in corporate charlist so that the string its pulling cannot contain any of the letters in it
SELECT * FROM table WHERE LENGTH(RTRIM(word)) = 8 AND word LIKE 'a__c____' AND word LIKE '%[!tesp]%' GROUP BY word
Basically I want this statement to pull up a word that is:
- 8 letters in length
- starts with “a” and 4th letter is “c”
- does not contain “t” “e” “s” “p” in it
Use the
REGEXP(or its synonymRLIKE) operator for this.The
[^tesp]{2}means “match 2 characters that are not t, e, s or p”.Note that the 8-letters is enforced by the regex. Also, it handles the
RTRIMby the*$at the end of the regex (allowing any number of spaces at the end).This lets you just do one pass over each word instead of three (once for
LENGTH, once forLIKE 'a__c____'and once for the “t”,”e”,”s”,”p”).