Select"/> Select">

Home >Database >Mysql Tutorial >How can we count the number of rows in a table using MySQL SELECT statement?

How can we count the number of rows in a table using MySQL SELECT statement?

王林
王林forward
2023-08-26 10:21:141549browse

我们如何使用 MySQL SELECT 语句来统计表中的行数?

We need to use the COUNT(*) function and the SELECT clause to count the total number of rows in the table.

Example

mysql> Select COUNT(*) from Student;

+----------+
| COUNT(*) |
+----------+
| 4        |
+----------+

1 row in set (0.06 sec)

The above query calculates the total number of rows in the "Student" table.

We can also use the WHERE clause with the COUNT(*) function as follows:

mysql> Select COUNT(*) from Student where Address = 'Delhi';

+----------+
| COUNT(*) |
+----------+
| 2        |
+----------+

1 row in set (0.00 sec)

The above is the detailed content of How can we count the number of rows in a table using MySQL SELECT statement?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete