Example 1
There is a table "Persons":
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Sanger |
Now we want to select all individuals who live in the city, whose name is begins
For this we use this query:
"%"
Query Result:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Sanger |
Example 2
Now we want to select all individuals who live in the city, whose name is
For this we use this query:
Query Result:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
Example 3
Now we want to select all individuals who live in the city, whose name is contains в себе буквы "". Не важно, в каком месте будут находиться данные символы, в начале или конце слова.
Query Result:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 3 | Pettersen | Kari | Storgt 20 | Sanger |
Now we want to select all individuals who live in the city, whose name is not contains в себе буквы "". Используем ключевое слово NOT.
Query Result:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |






Comments
SELECT *
FROM Persons
WHERE FirstName 'To_'
That would be the result of a query value Tom, Tos, Top but Tove, because it four characters, and you were asked to find meaning three.
dev.mysql.com /.../...
Something on the similarity of the
SELECT * FROM doc WHERE item '%a%'+(NOT '%b%')+'%c%'
which shows that between the characters 'a' and 'c' is not unusual and should be the symbol 'b' Quote
Why put one condition to another. it is obvious that they should work konyunktsiya:
… WHERE item %a%c% AND item NOT %a%b%c% Quote