Difference between revisions of "COUNT()"

From Lianjapedia
Jump to: navigation, search
 
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Returns the number of rows in a SELECT statement query
 
Returns the number of rows in a SELECT statement query
 
  
 
==Syntax==
 
==Syntax==
 
COUNT(* | [DISTINCT] <expr>)
 
COUNT(* | [DISTINCT] <expr>)
 
  
 
==See Also==
 
==See Also==
 
[[SQL Aggregate Functions|AGGREGATES]], [[AVG()]], [[SQL MAX()|MAX()]], [[SQL MIN()|MIN()]], [[SQL SELECT|SELECT]], [[SUM()]]
 
[[SQL Aggregate Functions|AGGREGATES]], [[AVG()]], [[SQL MAX()|MAX()]], [[SQL MIN()|MIN()]], [[SQL SELECT|SELECT]], [[SUM()]]
 
  
 
==Description==
 
==Description==
 
Returns the number of rows in the query.  If you specify DISTINCT, then only the rows which are unique in <expr> are counted.  Specifying <expr> on its own returns the number of rows from the query for which <expr> is not NULL.  If you specify the asterisk (*), then all rows are counted.
 
Returns the number of rows in the query.  If you specify DISTINCT, then only the rows which are unique in <expr> are counted.  Specifying <expr> on its own returns the number of rows from the query for which <expr> is not NULL.  If you specify the asterisk (*), then all rows are counted.
 
  
 
==Example==
 
==Example==
Line 28: Line 24:
  
  
==Products==
 
Recital Server, Recital
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL]]
 
[[Category:SQL]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:SQL Functions]]
 
[[Category:SQL Functions]]

Latest revision as of 07:49, 7 December 2012

Purpose

Returns the number of rows in a SELECT statement query

Syntax

COUNT(* | [DISTINCT] <expr>)

See Also

AGGREGATES, AVG(), MAX(), MIN(), SELECT, SUM()

Description

Returns the number of rows in the query. If you specify DISTINCT, then only the rows which are unique in <expr> are counted. Specifying <expr> on its own returns the number of rows from the query for which <expr> is not NULL. If you specify the asterisk (*), then all rows are counted.

Example

// Get a count of all rows in the accounts table.
SELECT COUNT(*) Total FROM accounts
 
// Get a count of jobs
SELECT COUNT(jobs) Jobs FROM employee
 
// Get a count of distinct rows for jobs
SELECT COUNT(DISTINCT jobs) Jobs FROM employee