
- 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
How to get number of rows in a table without using count(*) MySQL query?
You can use count(1). Let us first see the syntax −
select count(1) from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( StudentName varchar(100) ); Query OK, 0 rows affected (0.84 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(StudentName) values('John Smith'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(StudentName) values('Chris Brown'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('David Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentName) values('Carol Taylor'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------------+ | StudentName | +--------------+ | John Smith | | Chris Brown | | David Miller | | Carol Taylor | +--------------+ 4 rows in set (0.00 sec)
Following is the query to get number of rows in a table without using count(*) −
mysql> select count(1) from DemoTable;
Output
+----------+ | count(1) | +----------+ | 4 | +----------+ 1 row in set (0.03 sec)
- Related Articles
- MySQL - How to count all rows per table in one query?
- Fastest way to count number of rows in MySQL table?
- Count number of rows in each table in MySQL?
- Easiest way to get number of rows in a MySQL table?
- MySQL query to count number of duplicate values in a table column
- How can we use MySQL SELECT statement to count number of rows in a table?
- How to count number of rows in a table with jQuery?
- Get the count of two table fields in a single MySQL query?
- Get the number of rows in a particular table with MySQL
- How to get multiple rows in a single MySQL query?
- MySQL query to count rows with mutual relation using JOIN?
- MySQL query to count rows in multiple tables
- How to count rows from two tables in a single MySQL query?
- MySQL query to count rows with a specific column?
- How can we get the total number of rows affected by MySQL query?

Advertisements