티스토리 뷰

🌈 MsSql

count(*) 와 count(column)의 차이점

James Wetzel 2024. 5. 8. 11:07

In Microsoft SQL Server, the `COUNT(*)` and `COUNT(column)` functions are both used to count the number of rows in a table or a result set. However, they have a subtle difference:

1. **COUNT(*)**: This function counts the total number of rows in a table, including rows with NULL values in any column.

   Example:
   ```
   SELECT COUNT(*) FROM TableName;
   ```

2. **COUNT(column)**: This function counts the number of non-NULL values in the specified column.

   Example:
   ```
   SELECT COUNT(column) FROM TableName;
   ```

So, if you want to count all rows regardless of the values in a particular column, use `COUNT(*)`. If you want to count only the non-NULL values in a specific column, use `COUNT(column)`.

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함