- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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)
- Related Articles
- Fastest way to count number of rows in MySQL table?
- Easiest way to copy values of one column to a new table in MySQL?
- Get the number of rows in a particular table with MySQL
- What is the fastest way to insert a large number of rows into a MySQL table?
- How to get number of rows in a table without using count(*) MySQL query?
- The easiest way to insert date records in MySQL?
- What is the easiest way to store date in MySQL database?
- Count number of rows in each table in MySQL?
- Get number of fields in MySQL table?
- Easiest way to sort an array in MongoDB
- Get the number of columns in a MySQL table?
- What is the most efficient way to select a specific number of random rows in MySQL?
- Get at least x number of rows in MySQL?
- Can we get total number of rows in a MySQL database?
- Copy all rows of a table to another table in MySQL?

Advertisements