Home >Database >Mysql Tutorial >What does * mean in mysql

What does * mean in mysql

下次还敢
下次还敢Original
2024-04-26 07:21:151092browse

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>

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

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

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>

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>

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>

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>

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>

This is equivalent to:

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

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!

Statement:
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