Home > Database > Mysql Tutorial > body text

How does mysql count how many pieces of data there are in a table?

青灯夜游
Release: 2021-12-28 17:24:52
Original
22429 people have browsed it

In mysql, you can use the "select" statement and the count() function to count how many pieces of data there are in the table. This function can count the total number of record rows contained in the data table. The syntax "select count (* ) from data table name;".

How does mysql count how many pieces of data there are in a table?

The operating environment of this tutorial: windows10 system, mysql8 version, Dell G3 computer.

There is a Carsys database on the hard disk. There is a Brand table in the database. Now we need to query how many records there are in the Brand table.

As can be observed from the figure below, the Carsys database has a Brand table with 4 fields, namely ID, DeviceNo, BrandId, and BrandName.

The operation process is described in detail below.

1. Execute MySQL 8.0 Command Line Client

2. Enter the password

3. Enter use carsys

4. Enter select count (*) from Brand;

Instructions:

MySQL COUNT() function counts the total number of record rows contained in the data table, or returns the number of data rows contained in the column based on the query results. There are two ways to use it:

  • COUNT(*) Counts the total number of rows in the table, regardless of whether a column has a value or a null value.

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

[Related recommendations: mysql video tutorial]

The above is the detailed content of How does mysql count how many pieces of data there are in a table?. 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!