How to count the number of rows in a table in MySQL?
The examples use the students table from our MySQL tutorial: id, name, city, marks, course_id.
SELECT COUNT(*) AS total FROM students;
SELECT COUNT(*) AS delhi FROM students WHERE city = 'Delhi';
SELECT COUNT(DISTINCT city) AS cities FROM students;
Tutorials Class - Output Window
| total | delhi | cities |
|---|---|---|
| 6 | 2 | 4 |
The three results are 6 rows in the table, 2 students from Delhi and 4 different cities. See Aggregate Functions.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |