Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Wildcards * and %

Tags:

sql

mysql

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)"

like image 904
Russell Dias Avatar asked Jun 18 '10 14:06

Russell Dias


People also ask

What is %s and %D in MySQL?

%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.

What does * mean in MySQL?

It's a wildcard it means return all columns for that table in the result set.

Is * a wildcard in SQL?

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.

What are the two wildcard characters used in MySQL?

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.


2 Answers

* 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.

like image 166
Björn Avatar answered Sep 23 '22 09:09

Björn


"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.

like image 41
Lance Avatar answered Sep 19 '22 09:09

Lance