Sql Select Count

Sql select count statement returns the number of records in a table.
In this sql select count tutorial we will use the sample table below for our sql select count statement examples.

We will count the number of rows (records) in the users table.


Users Table; tbl_users

id Name Email Password Age
1 John Doe johndoe@j.com e56Hdf-2 34
2 Jane Doe janedoe@j.com p59Hdf-2 32
2 Gary Doe garydoe@j.com y02Tdf-2 23

SQL Select Count Code

SELECT COUNT(*) FROM tbl_users

This sql query will return 1 row that contains the number of records from users table.

Query Result

3


Note that you can also filter results by using WHERE in your sql queries.


Selected Rows Count

SELECT COUNT(*) FROM tbl_users WHERE Age > 30

In this sql count query we only select the number of records where the age is bigger then 30 from users table.

Query Result

2


SQL SELECT COUNT Code Samples