It is also very easy to count the number
of records that meet a certain criteria. This function is
performed with the COUNT operator and follows the syntax:
SELECT COUNT (column_name)
FROM table_name
WHERE where_clause [optional];
In other words, to count the number
of employees in the EMPLOYEES table,
you would use:
SELECT COUNT (EMP_NAME)
FROM EMPLOYEES;
which would return the following:
COUNT (EMP_NAME)
-----------------
3
-----------------
Note that sometimes, it is preferable
to use SELECT COUNT(*) instead of specifying a column_name.
This is because the COUNT operator does not consider columns
with null values. Thus, if you specified a column_name and one
of the rows in that table had a null value for column_name,
your count would be off. Using "*" assures that all rows are
counted even if they include null values. And by the way,
most implementations of SQL will also require you to use the
DISTINCT operator if you specify a column_name