
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get the number of rows in a particular table with MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> LastName varchar(100) -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Miller'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Taylor'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Brown'); Query OK, 1 row affected (0.29 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+----------+ | LastName | +----------+ | Smith | | Miller | | Taylor | | Brown | +----------+ 4 rows in set (0.00 sec)
Following is the query to get the number of rows in a particular table in the database “web” −
mysql> select table_rows from INFORMATION_SCHEMA.tables -> where table_schema='web' and table_name='DemoTable';
Output
This will produce the following output −
+------------+ | TABLE_ROWS | +------------+ | 4 | +------------+ 1 row in set (0.16 sec)
- Related Articles
- Easiest way to get number of rows in a MySQL table?
- How to get number of rows in a table without using count(*) MySQL query?
- Get the number of columns in a MySQL table?
- Count number of rows in each table in MySQL?
- In MySQL, how can we get the number code of a particular character?
- Get number of fields in MySQL table?
- Get at least x number of rows in MySQL?
- Can we get total number of rows in a MySQL database?
- Create a stored procedure to get the detail of a particular MySQL table stored in a database?
- Fastest way to count number of rows in MySQL table?
- Delete only specific rows in a table with MySQL
- How to get the values of a particular row in a table in Selenium with python?
- Fetch random rows from a table with MySQL
- Get rows that have common value from the same table with different id in MySQL
- How to count number of rows in a table with jQuery?

Advertisements