Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
SQL SELECT COUNT

SQL SELECT COUNT: A Comprehensive Guide

Posted on January 22, 2025January 22, 2025 By Rishabh saini No Comments on SQL SELECT COUNT: A Comprehensive Guide

SQL SELECT COUNT

The SQL COUNT() function is a powerful and widely used feature to retrieve the number of records in a table. It simplifies tasks where manually counting entries would be tedious. Whether you’re working with a database of customers, products, or employees, COUNT() helps fetch accurate results efficiently.

For example, consider you have a table of registered voters in a city and need to count the total voters. Instead of manual counting, you can use SQL’s COUNT() function to achieve this instantly.

Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click here

Syntax of SQL COUNT Function

SELECT COUNT(column_name) FROM table_name;  

In the syntax above:

  • Replace column_name with the name of the column you want to count.
  • Replace table_name with the name of your table.

Examples of SQL COUNT Function

Example 1: Counting Non-NULL Values in a Column

Consider a table named Vehicles with the following data:

Vehicle_NameVehicle_TypePrice
Tesla Model 3Electric45,000
Honda CivicSedanNULL
Ford MustangSports60,000
Toyota CorollaSedan25,000
Nissan LeafElectricNULL
BMW X5SUV80,000

To count the total non-NULL Price values:

SELECT COUNT(Price) AS TotalPrices FROM Vehicles;  

Output:

TotalPrices
4

Here, COUNT(Price) excludes the NULL values, so only four rows are counted.

Example 2: Counting Total Entries in a Table

Using the same Vehicles table, if you want to count all entries, regardless of whether Price is NULL or not:

SELECT COUNT(*) AS TotalVehicles FROM Vehicles;  

Output:

TotalVehicles
6

The COUNT(*) function includes both NULL and non-NULL values.

SQL COUNT with the WHERE Clause

You can combine COUNT() with the WHERE clause to count rows meeting specific criteria.

Example 1: Counting Rows Based on Condition

From the Vehicles table, to count the number of electric vehicles:

SELECT COUNT(Vehicle_Name) AS ElectricVehicles FROM Vehicles WHERE Vehicle_Type = 'Electric';  

Output:

ElectricVehicles
2

Example 2: Counting Based on Another Condition

Consider another table EmployeeRecords:

Emp_IDEmp_NameSalaryCity
1001Priya60,000Mumbai
1002Amit50,000Delhi
1003Ravi70,000Mumbai
1004Sneha40,000Bangalore
1005Arjun60,000Mumbai

To count employees based in Mumbai:

SELECT COUNT(Emp_Name) AS EmployeesInMumbai FROM EmployeeRecords WHERE City = 'Mumbai';  

Output:

EmployeesInMumbai
3

SQL COUNT with DISTINCT

To count only unique values, use the DISTINCT keyword with COUNT().

Example: Counting Unique Cities

From the EmployeeRecords table, count the unique cities employees belong to:

SELECT COUNT(DISTINCT City) AS UniqueCities FROM EmployeeRecords;  

Output:

UniqueCities
3

The three unique cities are Mumbai, Delhi, and Bangalore.

Download New Real Time Projects :-Click here

Conclusion

The SQL COUNT() function is a robust tool for handling data efficiently, offering the ability to count specific or all entries in a table. Its combination with clauses like WHERE and keywords like DISTINCT further enhances its capabilities.

For more professional database management tips, stay connected with UpdateGadh!


sql select count group by
sql select count(distinct)
select count(*) from table
count number of rows in sql query result
sql count with condition
count(1) in sql
sql count if
sql average group by
sql
sql join
sql select count row
sql select count example
sql select count oracle
sql select count w3schools

Post Views: 655
SQL Tutorial Tags:aggregate functions, becoming a data scientist, becomingads.com, best, coding, column count in sql, column count sql, count of columns in sql, count(*), Data Science, data scientist, get column count in sql, get column count sql, get sql column count, how to get column count in sql, knowstar, mssql, postgresql aggregation, prog1735, rapid tutor, sql, sql aggregation, sql column count, sql count, sql max, sql min, sql sum, training, tsql, Tutorial

Post navigation

Previous Post: Is Python a Scripting Language?
Next Post: Event Management System Using Spring Boot

More Related Articles

GROUP BY vs. ORDER BY in SQL GROUP BY vs ORDER BY in SQL SQL Tutorial
SQL DELETE DATABASE SQL DELETE DATABASE – A Complete Guide SQL Tutorial
SQL OUTER JOIN SQL OUTER JOIN: A Comprehensive Guide SQL Tutorial

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Understanding the SQL DELETE Statement and Its Variants
  2. SQL Temporary Tables: A Handy Tool for Developers
  3. SQL WITH Clause
  4. SQL UPDATE with JOIN
  5. Understanding SQL CROSS JOIN with Examples
  6. IN vs EXISTS in SQL: A Complete Guide

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Blog Site In PHP And MYSQL With Source Code || Best Project
  9. Online Bike Rental Management System Using PHP and MySQL
  10. E learning Website in php with Free source code
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Agentic RAG AI System Using Python – Complete Final Year Project Guide
  • AI-Powered Online Examination System with Face Detection Using PHP & MySQL
  • Real-Time Medical Queue & Appointment System with Django
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital

Most Viewed Posts

  • Top Large Language Models in 2025 (8,631)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,248)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,911)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme