- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Easiest way to get number of rows in a MySQL table?
The easiest way to get number of rows, use aggregate function COUNT(*). Let us first create a table −
mysql> create table DemoTable1575 -> ( -> FirstName varchar(20) -> ); Query OK, 0 rows affected (1.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1575 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1575 values('Robert'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1575;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Chris | | Bob | | Adam | | Robert | +-----------+ 4 rows in set (0.00 sec)
Here is how to get the number of rows −
mysql> select count(*) from DemoTable1575;
This will produce the following output −
+----------+ | count(*) | +----------+ | 4 | +----------+ 1 row in set (0.03 sec)
Advertisements