You already know the percent sign
%. Now we will complete your knowledge with the second wildcard - the underscore _ - and with the negation of a pattern: NOT LIKE.The
_ character replaces exactly one arbitrary character (no more, no less):1SELECT * FROM autorzy
2WHERE imie LIKE 'J_n';This matches e.g. Jan, Jon - three letters, where the first is J, the last is n, and the middle one is arbitrary. It will not match Jaan (four letters) nor Jn (two letters), because each
_ is exactly one character.| Character | Meaning | |-----------|---------| |
% | any sequence of characters (including empty) |
| _ | exactly one arbitrary character |They can be combined, e.g.
'A_%' means: starts with A, then exactly one arbitrary character, and then anything.To find rows that do not match the pattern, we use NOT LIKE:
1SELECT * FROM ksiazki
2WHERE tytul NOT LIKE 'O%';This means: "Titles that do NOT start with the letter O". The
NOT operator reverses the action of LIKE, just as it reversed an ordinary condition.Thanks to
%, _ and NOT LIKE you have full control over pattern searching, @name. No scroll will hide from the eye of an experienced scribe!