Home > Database > SQL > body text

Usage of * in sql

下次还敢
Release: 2024-04-28 11:00:24
Original
412 people have browsed it

* in SQL is a wildcard character with the following usage: query all columns: SELECT * FROM table_name; alias for all columns: SELECT * AS all_columns FROM table_name; find specific values ​​in the WHERE clause: SELECT FROM table_name WHERE LIKE '%value%'; Used with aggregate functions: SELECT SUM(*) FROM table_name;

Usage of * in sql

##Usage of * in SQL

The * (asterisk) in SQL is a wildcard character that has a wide range of uses in various queries.

Query all columns

    The most common usage is to retrieve all columns in the table. For example:
<code class="sql">SELECT * FROM table_name;</code>
Copy after login
This query will return the values ​​of all columns in the table.

Alias ​​for all columns

    You can add an alias for * to easily reference all columns:
<code class="sql">SELECT * AS all_columns FROM table_name;</code>
Copy after login
This query A virtual column named "all_columns" will be returned that contains all column values ​​in the table.

Use * in the WHERE clause

    You can use * to find any column with a specific value in the WHERE clause. For example:
<code class="sql">SELECT * FROM table_name WHERE * LIKE '%value%';</code>
Copy after login
This query will return all column values ​​that contain the "value" string.

Using * with aggregate functions

    You can use * with aggregate functions (such as SUM, COUNT) to calculate the sum or count of all columns. For example:
<code class="sql">SELECT SUM(*) FROM table_name;</code>
Copy after login
This query will return the sum of all numeric columns in the table.

Notes

  • You should pay attention to the following when using *:

      It can cause query performance to degrade, Because all columns need to be retrieved.
    • It does not work with join queries across multiple tables.

The above is the detailed content of Usage of * in sql. 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!