SQL COUNT() Function - The Coding Shala
Home >> Learn SQL >> SQL COUNT() Function
The following 'emp' is used for the examples -
The following SQL query will count the employees who live in the city 'Pune' -
SQL COUNT() Function
The SQL COUNT() function returns the number of rows(count of rows) which are returned by the SELECT statement.
SQL COUNT() Syntax
The basic syntax of SQL COUNT() is as follows -
SELECT COUNT(column_name) FROM table_name WHERE condition;
The following 'emp' is used for the examples -
emp_id emp_name city dept_no salary 1 Akshay Pune 101 50000 3 Nikhil Pune 101 51000 5 Mohit Delhi 103 40000 6 Shubham Surat 105 42000 7 Akash Mumbai 106 45000
SQL COUNT() Examples
The following SQL query will return the number of records present in the emp table using the COUNT() function. We can use column name with count() function like count(emp_name) or can use count(*) that count all the records that returned by the SELECT statement.
SQL >> select count(*) from emp; Output >> count(*) 5
The following SQL query will count the employees who live in the city 'Pune' -
SQL >> select count(emp_name) from emp where city = 'Pune'; Output >> count(emp_name) 2
Other Posts You May Like
Comments
Post a Comment