×
×
SQL Tutorial
What is SQL SQL SELECT SQL SELECT DISTINCT SQL WHERE SQL INSERT SQL UPDATE SQL DELETE SQL AND, OR & NOT Clause SQL ORDER BY SQL LIKE Clause SQL IN Operator SQL BETWEEN Operator SQL MAX() and MIN() SQL COUNTSQL JOIN
SQL JOIN SQL INNER JOIN SQL LEFT JOIN SQL RIGHT JOIN SQL FULL OUTER JOINSQL COUNT
The COUNT() function returns the number of rows in the result set.
Syntax:
SELECT COUNT(column_name) FROM table_name WHERE condition;
Example Database:
This is employee table.
id | name | salary | hire date |
---|---|---|---|
1 | Kailash | 20000 | 2022-12-10 |
2 | Amit | 5000 | 2022-07-15 |
3 | Siddarth | 15000 | 2022-03-23 |
4 | Amit | 30000 | 2022-08-20 |
Example 1: COUNT()
Find total entries in employee table using count.
SQL:
SELECT COUNT(*) FROM employee;
Result:
COUNT(*) |
---|
4 |
Example 2: Aliases with COUNT()
Find total entries in employee table using count as alias.
SQL:
SELECT COUNT(*) as TOTAL FROM employee;
Result:
TOTAL |
---|
4 |
Example 3: COUNT() with WHERE
SQL:
SELECT COUNT(name) AS TOTAL
FROM employee
WHERE name = 'Amit';
Result:
TOTAL |
---|
2 |
Example 4: COUNT() with DISTINCT
If we need to count the number of unique rows, we can use the COUNT() function with the DISTINCT clause
SQL:
SELECT COUNT(DISTINCT name)
FROM employee;
Result:
COUNT(DISTINCT name) |
---|
3 |
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date
Copyright 2018 - 2025 Elevenstech Web Tutorials All rights reserved.