Home > Database > Mysql Tutorial > body text

What does * mean in mysql

下次还敢
Release: 2024-04-26 07:21:15
Original
1040 people have browsed it

In MySQL, the meaning of *

The asterisk (*) in MySQL represents "all". It has different uses in different contexts.

1. Select all columns

Use * to select all columns in the table:

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

It is equivalent to writing out all columns in the table Name of:

<code class="sql">SELECT column1, column2, ..., columnN FROM table_name;</code>
Copy after login

2. Select all rows

In a subquery, * can be used to select all rows from the main query:

<code class="sql">SELECT * FROM (SELECT * FROM table_name WHERE condition) AS subquery;</code>
Copy after login

3. JOIN table

In the JOIN statement, * can be used to specify the connection of all rows:

<code class="sql">SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;</code>
Copy after login

4. Wildcard character

In the LIKE clause, * can be used as a wildcard character, matching 0 or more characters:

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

It will match any row containing "john" in the name.

5. Regular expression

In the REGEXP clause, * can be used as a quantifier to match the previous pattern 0 or more times:

<code class="sql">SELECT * FROM table_name WHERE name REGEXP '.*john.*';</code>
Copy after login

It will match any name that starts or ends with "john".

6. Implicit conversion

In some cases, MySQL will automatically convert * to other types. For example, in a numeric context, it will be converted to a number:

<code class="sql">SELECT * FROM table_name WHERE id = 10;</code>
Copy after login

This is equivalent to:

<code class="sql">SELECT * FROM table_name WHERE id = 10.0;</code>
Copy after login

In summary, the asterisk (*) in MySQL means "all", in a different context have different meanings. It is typically used to select all columns, rows, or as a wildcard or quantifier in JOIN, LIKE, and REGEXP clauses.

The above is the detailed content of What does * mean 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!