---
title: "Difference between COUNT(*) vs COUNT(column)."  
description: "Difference between COUNT(*) vs COUNT(column)."  
author: "ICSM Computer"  
published: 2026-05-08  
updated: 2026-05-08  
canonical: https://www.mindstick.com/interview/34506/difference-between-count-vs-count-column  
category: "database"  
tags: ["database", "sql server"]  
reading_time: 3 minutes  

---

# Difference between COUNT(*) vs COUNT(column).

In SQL, both `COUNT(*)` and `COUNT(column)` count rows, but they behave differently with `NULL` values.

## `COUNT(*)`

Counts **all rows** in the result set, including rows where columns contain `NULL`.

Example:

```plaintext
SELECT COUNT(*) FROM employees;
```

If the table has 10 rows, result = `10`.

## `COUNT(column)`

Counts only rows where the specified column is **NOT NULL**.

Example:

```plaintext
SELECT COUNT(email) FROM employees;
```

If `email` has:

| id | email |
| --- | --- |
| 1 | [a@example.com](mailto:a@example.com) |
| 2 | NULL |
| 3 | [b@example.com](mailto:b@example.com) |

Then:

```plaintext
COUNT(email) = 2
COUNT(*) = 3
```

## Key Difference

| Function | Counts NULLs? | What it counts |
| --- | --- | --- |
| `COUNT(*)` | Yes | All rows |
| `COUNT(column)` | No | Non-NULL values in that column |

## With `GROUP BY`

Example:

```plaintext
SELECT department_id, COUNT(*), COUNT(manager_id)
FROM employees
GROUP BY department_id;
```

- `COUNT(*)` → total employees in each department
- `COUNT(manager_id)` → employees whose `manager_id` is not NULL

## Performance Notes

In modern databases (like PostgreSQL, MySQL, SQL Server, Oracle):

- `COUNT(*)` is usually optimized and preferred for counting rows.
- `COUNT(1)` and `COUNT(*)` are generally equivalent in performance.
- `COUNT(column)` may behave differently because it must check for NULLs.

## Quick Rule

Use:

- `COUNT(*)` → when you want total row count
- `COUNT(column)` → when you want count of non-null values in a specific column

## Answers

### Answer by ICSM Computer

In SQL, both `COUNT(*)` and `COUNT(column)` count rows, but they behave differently with `NULL` values.

## `COUNT(*)`

Counts **all rows** in the result set, including rows where columns contain `NULL`.

Example:

```plaintext
SELECT COUNT(*) FROM employees;
```

If the table has 10 rows, result = `10`.

## `COUNT(column)`

Counts only rows where the specified column is **NOT NULL**.

Example:

```plaintext
SELECT COUNT(email) FROM employees;
```

If `email` has:

| id | email |
| --- | --- |
| 1 | [a@example.com](mailto:a@example.com) |
| 2 | NULL |
| 3 | [b@example.com](mailto:b@example.com) |

Then:

```plaintext
COUNT(email) = 2
COUNT(*) = 3
```

## Key Difference

| Function | Counts NULLs? | What it counts |
| --- | --- | --- |
| `COUNT(*)` | Yes | All rows |
| `COUNT(column)` | No | Non-NULL values in that column |

## With `GROUP BY`

Example:

```plaintext
SELECT department_id, COUNT(*), COUNT(manager_id)
FROM employees
GROUP BY department_id;
```

- `COUNT(*)` → total employees in each department
- `COUNT(manager_id)` → employees whose `manager_id` is not NULL

## Performance Notes

In modern databases (like PostgreSQL, MySQL, SQL Server, Oracle):

- `COUNT(*)` is usually optimized and preferred for counting rows.
- `COUNT(1)` and `COUNT(*)` are generally equivalent in performance.
- `COUNT(column)` may behave differently because it must check for NULLs.

## Quick Rule

Use:

- `COUNT(*)` → when you want total row count
- `COUNT(column)` → when you want count of non-null values in a specific column


---

Original Source: https://www.mindstick.com/interview/34506/difference-between-count-vs-count-column

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
