What is the difference between %
and *
wildcards in MySQL?
In a query like so : "SELECT * FROM $table WHERE MATCH (message) AGAINST('$string*' IN BOOLEAN MODE)"
%d – the argument is treated as an integer, and presented as a (signed) decimal number. %s – the argument is treated as and presented as a string. in your examples, $slug is a string and $this->id is an integer.
It's a wildcard it means return all columns for that table in the result set.
SQL supports two wildcard operators in conjunction with the LIKE operator which are explained in detail in the following table. Sr.No. Matches one or more characters. Note − MS Access uses the asterisk (*) wildcard character instead of the percent sign (%) wildcard character.
MySQL provides two wildcard characters for constructing patterns: percentage % and underscore _ . The percentage ( % ) wildcard matches any string of zero or more characters. The underscore ( _ ) wildcard matches any single character.
*
can only be used as a wildcard (or truncation) in a full text search while %
(match 0 or more characters) and _
(match exactly one character) are only applicable in LIKE-queries.
"An asterisk is the truncation operator. Unlike the other operators, it is appended to the word, or fragment, not prepended."
This only applies to MATCH() ... AGAINST()
statements.
The %
is a LIKE
wildcard and has nothing to do with the MATCH() ... AGAINST()
.
I hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With