Counting Rows in a Table
You can count rows in a table to determine:
- The total number of rows in a table, for example, a count of all the books in a
titles
table. - The number of rows in a table that meet a specific condition, for example, the number of books by one publisher in a
titles
table. - The number of values in a particular column.
When you count values in a column, nulls are not included in the count. For example, you might count the number of books in a titles
table that have values in the advance
column. By default, the count includes all values, not just unique values.
The procedures for all three types of counts are similar.
To count all the rows in a table
- Be sure the table you want to summarize is already present in the Diagram pane.
- Right-click the background of the Diagram pane, then choose Group By from the shortcut menu. The Query Designer adds a Group By column to the grid in the Grid pane.
- Select * (All Columns) in the rectangle representing the table or table-structured object.
The Query Designer automatically fills the term Count into the Group By column in the Grid pane and assigns a column
alias to the column you are summarizing. You can replace this automatically generated alias with a more meaningful one. For more details, see Creating Column Aliases.
To count all the rows that meet a condition
- Be sure the table you want to summarize is already present in the Diagram pane.
- Right-click the background of the Diagram pane, then choose Group By from the shortcut menu. The Query Designer adds a Group By column to the grid in the Grid pane.
- Select * (All Columns) in the rectangle representing the table or table-structured object.
The Query Designer automatically fills the term Count into the Group By column in the Grid pane and assigns a column alias to the column you are summarizing. To create a more useful column heading in query output, see Creating Column Aliases.
- Add the data column that you want to search, and then clear the check box in the Output column.
The Query Designer automatically fills the term Group By into the Group By column of the grid.
- Change Group By in the Group By column to Where.
- In the Criteria column for the data column to search, enter the search condition.
To count the values in a column
- Be sure the table you want to summarize is already present in the Diagram pane.
- Right-click the background of the Diagram pane, then choose Group By from the shortcut menu. The Query Designer adds a Group By column to the grid in the Grid pane.
- Add the column that you want to count to the Grid pane.
The Query Designer automatically fills the term Group By into the Group By column of the grid.
- Change Group By in the Group By column to Count.
Note To count only unique values, choose Count Distinct.
See Also
Summarizing and Grouping | Summarizing Values for All Rows in a Table | Summary and Grouping Behavior in the Query Designer