Home > Database > Mysql Tutorial > body text

How to check the number of data items in mysql?

青灯夜游
Release: 2020-10-19 10:56:24
Original
10046 people have browsed it

In mysql, you can use the COUNT() function to check the number of data records. The syntax is "SELECT COUNT(*) AS alias FROM data table name;"; the COUNT() function can count the records contained in the data table. The total number of rows, or the number of data rows contained in the returned column based on the query results.

How to check the number of data items in mysql?

(Recommended tutorial: mysql video tutorial)

MySQL COUNT() function statistics records contained in the table The total number of rows, or the number of data rows contained in the column returned according to the query results. There are two ways to use it:

  • COUNT(*) Calculate the total number of rows in the table, regardless of a certain The column has a numeric value or is empty.

  • COUNT (field name) calculates the total number of rows under the specified column. Rows with null values ​​will be ignored during calculation.

[Example] Query the total number of rows in the tb_students_score table. The input SQL statement and execution results are as follows.

mysql> SELECT COUNT(*)
    -> AS students_number
    -> FROM tb_students_score;
+-----------------+
| students_number |
+-----------------+
|              10 |
+-----------------+
1 row in set (0.03 sec)
Copy after login

As you can see from the query results, COUNT(*) returns the total number of rows recorded in the tb_students_score table, no matter what the value is. The total number returned is named students_number.

The above is the detailed content of How to check the number of data items 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