Reputation: 724
I saw a select statement with something like this in the where part 'LIKE %Blabla%Another%', now I tried it myself and I don't clearly understand how it works. The thing I'm confused about is the % in the middle, I understand how '%Blabla Another%' works, but with the % as a replacement for the space, I got confused.
Upvotes: 1
Views: 1870
Reputation:
Here is a listing of the wildcards that you can use and below some examples.
The following SQL statement selects all customers with a City containing the pattern "es"
The following SQL statement selects all customers with a City starting with any character, followed by "erlin":
The following SQL statement selects all customers with a City starting with "b", "s", or "p":
The following SQL statement selects all customers with a City NOT starting with "b", "s", or "p":
Source: http://www.w3schools.com/sql/sql_wildcards.asp
Upvotes: 0
Reputation: 372
In SQL, wildcard characters are used with the SQL LIKE operator.
there are the wild cards in sql %,_,[charlist],[^charlist].
the % wild cards is a substitute for zero or more characters.
for example
SELECT * FROM Customers
WHERE City LIKE '%es%';
this will selects all customers with a City containing the pattern "es".
so here you can see that the % wild card act as null or space character.
Upvotes: 0
Reputation: 17228
With LIKE you can use the following two wildcard characters in the pattern:
% matches any number of characters, even zero characters.
_ matches exactly one character.
Upvotes: 0
Reputation: 987
% means any (including none) chars.
If you have a string 'abcdef' it would match e.g 'a%f' since the string start and ends with a and f.
'%b%e%'would also match as it means any string with b and even, in that order, but not necessarily next to each other
Upvotes: 0
Reputation: 311163
%
means "any sequence of characters, including an empty one". So LIKE '%Blabla%Another%'
will match, for example 'XYZBlablaABCAnotherPQR'
, 'BlablaAnother'
and ' Blabla Another '
Upvotes: 2