count() in SQL

Syntax of using count() :

Count () can be used in SELECT statement as well as in GROUP BY clause.

SELECT COUNT(EXPRESSION) FROM TABLE_NAME;
SELECT COLUMN_NAME,COUNT(EXPRESSION) FROM TABLE_NAME GROUP BY COLUMN_NAME HAVING COUNT(EXPRESSION) RELATIONAL_OPERATOR VALUE;
emid	ename	cmpny
NULL NULL 0
NULL NULL 0
NULL NULL 0
SELECT count(*)
FROM [tb_emp_table]
3
emid	ename	cmpny
NULL NULL 0
NULL NULL 0
NULL NULL 0
SELECT count(1)
FROM [tb_emp_table]
3
emid	ename	cmpny
NULL NULL 0
NULL NULL 0
NULL NULL 0
SELECT count(empid)
FROM [tb_emp_table]
0

note:-

Data:-
emid ename cmpny
1 Vihal tcs
2 XYZ0 wipro
3 XYZ 3i
4 Aarsh tcs
5 XYZ1 tcs

SELECT count(
case
when cmpny='tcs' then
emid
end)
FROM [tb_emp_table];

result:-
3

--

--

--

love ❤ coding, solving some industry problems technologies: JavaScript, C#, Angular, PLSQL, Docker Want to learn: Python, Go language, AI, ML and Cloud

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

PARSIQ Community Team Expansion

Mobile Development -Native or Cross Platform

Terraforming an AWS VPC — Part 3

Top 5 Programming Languages to learn in 2021

Serving Private Content of S3 through CloudFront Signed URL

Linked List in Python

10 Best Online Agile Tools List For Project Management In 2022

Running cron jobs in the cloud — Amazon EC2 vs AWS Lambda

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vishal Pathak

Vishal Pathak

love ❤ coding, solving some industry problems technologies: JavaScript, C#, Angular, PLSQL, Docker Want to learn: Python, Go language, AI, ML and Cloud

More from Medium

Triggers in MS SQL Server

GitHub— basic commands

Triggers in SQL and What is DML Trigger

Intelligent Oracle SQL Commands