The meaning of asterisk in mysql

下次还敢
Release: 2024-04-27 05:27:13
Original
773 people have browsed it

The asterisk (*) is a wildcard character in MySQL and has the following meanings: Select all columns: In a SELECT statement, it selects all columns from the specified table. Match any sequence of characters: In the WHERE clause, it is used to match any sequence of characters, such as finding rows containing "John". Fuzzy queries: It can also be used for fuzzy queries, such as finding rows starting with "Jo".

The meaning of asterisk in mysql

The meaning of asterisk (*) in MySQL

The asterisk (*) is a wildcard character in MySQL, used to match any sequence of characters.

Detailed description:

  • Select all columns: In the SELECT statement, use the asterisk to select all columns from the specified table . For example:
<code class="sql">SELECT * FROM table_name;</code>
Copy after login
  • Matches any sequence of characters: In the WHERE clause, use an asterisk to match any sequence of characters. For example, the following query finds all rows that contain "John" in the name column:
<code class="sql">SELECT * FROM table_name WHERE name LIKE '%John%';</code>
Copy after login
  • Fuzzy queries: The asterisk can also be used for fuzzy queries. For example, the following query finds all rows that begin with "Jo" in the name column:
<code class="sql">SELECT * FROM table_name WHERE name LIKE 'Jo%';</code>
Copy after login

Example:

Suppose there is a table named customers, It contains the following columns:

  • id
  • name
  • address
  • phone

The following query uses asterisks Select all columns from the customers table:

<code class="sql">SELECT * FROM customers;</code>
Copy after login

The following query finds all rows that contain "Smith" in the name column:

<code class="sql">SELECT * FROM customers WHERE name LIKE '%Smith%';</code>
Copy after login

The following query finds all rows that begin with "123" in the address column :

<code class="sql">SELECT * FROM customers WHERE address LIKE '123%';</code>
Copy after login

The above is the detailed content of The meaning of asterisk in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!