By 25/02/2016 1 Comments

What Is COUNT() Function In SQL?

  • SQL COUNT() function is used for counting purpose of table rows. It returns the total number of rows/records in a database table.
  • SQL COUNT() function does not count a column which contains NULL values.

Syntax: Count values in a specific column

SELECT COUNT(column_name) FROM table_name;

Example:

SELECT COUNT(country_name) AS "Total countries"
FROM country;
  • In above example a COUNT(country_name) function returns the total number of countries in a table (country).

Syntax: Count all records (columns)

SELECT COUNT(*) FROM table_name;

Example:

SELECT COUNT(*) AS "Total records"
FROM country;
  • In above example a COUNT(*) function returns the total number of records in a table (country).

Syntax: Count unique/distinct values of a column

SELECT COUNT(DISTINCT column_name) FROM table_name;

Example:

SELECT COUNT(DISTINCT country_name) AS "Total Unique countries"
FROM country;
  • In above example a COUNT(DISTINCT country_name) function returns the total number of unique countriesĀ in a table (country).






Posted in: Sql

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .