Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Select Count in SQL

Select Count in SQL

? SELECT COUNT() in SQL

The COUNT() function returns the number of rows that match a specified condition or total rows in a table.


? Syntax:

SELECT COUNT(column_name) FROM table_name WHERE condition;

or to count all rows including those with NULL in a column:

SELECT COUNT(*) FROM table_name WHERE condition;

? Examples:

Count total rows in a table:

SELECT COUNT(*) AS total_employees FROM employees;

Count rows where salary is not NULL:

SELECT COUNT(salary) AS salary_count FROM employees;

Count employees in the 'Sales' department:

SELECT COUNT(*) AS sales_countFROM employeesWHERE department = 'Sales';

Count distinct departments:

SELECT COUNT(DISTINCT department) AS unique_departments FROM employees;

? Notes:

  • COUNT(*) counts all rows regardless of NULLs.

  • COUNT(column_name) counts non-NULL values in that column.

  • COUNT(DISTINCT column_name) counts unique non-NULL values.


Want me to show COUNT() with GROUP BY or joins?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql