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;".
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!