" /> Password <br /><input type="password" name="passwd" id="passwd" class="inputbox" size="18" alt="password" />
PDF

1
2
3
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE 

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:

1
2
SELECT * FROM Persons
WHERE City LIKE 's%'

"%"

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:

1
2
SELECT * FROM Persons
WHERE City LIKE '%s'

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 в себе буквы "". Не важно, в каком месте будут находиться данные символы, в начале или конце слова.

1
2
SELECT * FROM Persons
WHERE City LIKE '%%'

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.

1
2
SELECT * FROM Persons
WHERE City NOT LIKE '%%'

Query Result:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes

Comments

 
+20 #1 Шелест Константин 2010-10-29 17:48 You can also use the underscore character (_) to replace a single character in the value. For example, if you ask me:

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.
Quote
 
 
+7 #2 Трололо 2010-12-01 10:13 How to escape special characters? Quote
 
 
+2 #3 coel 2011-05-27 10:16
How to escape special characters?

dev.mysql.com /.../...
Quote
 
 
+1 #4 snarbi 2011-08-05 11:55 Is it possible to create multiple queries and NOT
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
 
 
+2 #5 vladmax 2011-09-01 18:25
Is it possible to create multiple queries and NOT
Something on the similarity of the
SELECT * FROM doc WHERE item \'%a%\'+(NOT \'%b%\')+\'%c%\'
which shows that between the characters \ 'a \' and \ 'c \' character is not unusual and should be \ 'b \'


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
 

Authorization

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Advertisement