{"id":104012,"date":"2021-08-04T11:00:00","date_gmt":"2021-08-04T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=104012"},"modified":"2022-02-24T12:09:55","modified_gmt":"2022-02-24T10:09:55","slug":"sql-count-function","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/","title":{"rendered":"SQL Count Function"},"content":{"rendered":"<p>In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like <code>GROUP BY<\/code> and <code>HAVING<\/code>.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>Many times, the information we want from a database table is not available in a single row but in a group of rows or in the result of a mathematical calculation. That is, the data in the group of rows need to be combined or a value expression calculated to obtain a single value of useful business information. To extract data in such cases, <code>SQL<\/code>  (Structured Query Language) provides us with operations that are called aggregate functions:  <code>AVG<\/code>, <code>COUNT<\/code>, <code>MIN<\/code>, <code>MAX<\/code>, <code>SUM<\/code>. All these aggregate functions return a single value.<\/p>\n<h2 class=\"wp-block-heading\">2. Salient Features<\/h2>\n<p><code>COUNT<\/code> is an aggregate function that counts the number of rows in each group. The most basic aggregation is when you specify a *, which will tell you how many rows are there in the result set, including rows containing duplicate and Null values.<\/p>\n<p>If you specify a column name, <code>COUNT<\/code> tells how many non-null values are present in the column.<\/p>\n<p>The <code>GROUP BY<\/code> clause runs after the <code>WHERE<\/code> clause has been evaluated. Here, we want the database server to group the result set into groups based on some column(s). These are specified using the <code>GROUP BY<\/code> keywords. The system will collect the rows with the same values in these specified columns, into a group. It is important to remember that the G<code>ROUP BY<\/code> clause refers to columns generated by the <code>FROM<\/code> and <code>WHERE<\/code> clauses and cannot use any expression that appears in the <code>SELECT<\/code> clause.<\/p>\n<p>For any queries, we will need to get extra columns along with columns generated by aggregate functions. These columns are added to the <code>SELECT<\/code> clause and should also be added in the <code>GROUP BY<\/code> clause.<\/p>\n<p>We need not specify columns in the <code>GROUP BY<\/code> clause. Instead, we can use ordinal positions that correspond to each column position in the <code>SELECT<\/code> part of the query.<\/p>\n<p>While the <code>COUNT<\/code> function determines the number of elements in each group, sometimes we may not want the duplicate values of a column from all members of the group. To achieve this, we use the <code>DISTINCT<\/code> keyword along with the column name. However, we cannot use <code>DISTINCT<\/code> with <code>COUNT(*)<\/code>.<\/p>\n<p>Sometimes, want to do second-level filtering on the grouped rows. For this, we use the <code>HAVING<\/code> operator to apply filter condition(s) on the grouped result set. The <code>HAVING BY<\/code> clause can be used without a <code>GROUP BY<\/code> clause in which case, the <code>HAVING BY<\/code> clause filters all rows returned from the <code>WHERE<\/code> clause as if they are a single group. One key point here is that the <code>WHERE<\/code> clause cannot have aggregate functions whereas the <code>HAVING<\/code> clause can contain.<\/p>\n<p>The <code>ORDER BY<\/code> keywords can be put at the end of a SQL statement. It sorts the data based on the columns specified to it. The default sorting is ascending order, so if we want to get the result set in reverse order, we use the keyword <code>DESC<\/code>.<\/p>\n<h2 class=\"wp-block-heading\">3. Tables and Data<\/h2>\n<p>We will use three tables to demonstrate the usage of queries using <code>COUNT<\/code>. The tables are: <code>departments<\/code> and  <code>employees<\/code> pertaining to the HR function and a <code>book_sales<\/code> table of a <code>book_store<\/code> database.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The following diagram shows the structure of these tables.<\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/tables.jpg\"><img decoding=\"async\" width=\"750\" height=\"395\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/tables.jpg\" alt=\"sql count - table structure\" class=\"wp-image-104022\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/tables.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/tables-300x158.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Database Table Structure<\/figcaption><\/figure>\n<p>In the <code>employees<\/code> table, each employee (including managers) has his\/her own <code>employee_id<\/code> and they have their manager\u2019s <code>employee_id<\/code> in the <code>manager_id<\/code> column. The department managers have their <code>manager_id<\/code> as <code>NULL<\/code>.<\/p>\n<p>The <code>book_store<\/code> database has six titles and monthly sales of each book are recorded in the <code>book_sales<\/code> table. The month column is an integer, so 1 is used for January and 12 for December. The <code>quantity<\/code> column has the sales number and if there are no sales of a particular book in the month, the <code>quantity<\/code> is zero. In effect, there are six rows every month, one per book.<\/p>\n<h2 class=\"wp-block-heading\">4. SQL Count Function &#8211; Examples<\/h2>\n<p>In this section, we demonstrate the usage of the <code>COUNT<\/code> function in <code>SELECT<\/code> queries on the data in the <code>employees<\/code> and <code>departments<\/code> tables as well as the <code>book_sales<\/code> table. For each example, we first state the business requirement and then show its implementation as a <code>SELECT<\/code> query. Along with some notes, screenshots of the result set are given below each query.<\/p>\n<h3>4.1 How many employees are there in each department?<\/h3>\n<pre class=\"brush:sql\">SELECT department_id \"Department Id\", COUNT(*) \"No. of employees\"\nFROM employees\nGROUP BY department_id;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query1.jpg\"><img decoding=\"async\" width=\"750\" height=\"527\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query1.jpg\" alt=\"sql count - wise employee count\" class=\"wp-image-104026\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query1.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query1-300x211.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Department-wise employee count<\/figcaption><\/figure>\n<h3>4.2 Which departments have employee count more than three?<\/h3>\n<p>For this requirement, we need to use <code>GROUP BY<\/code> and <code>HAVING<\/code> clauses.<\/p>\n<pre class=\"brush:sql\">SELECT department_id \"Department Id\", COUNT(*) \"No. of employees\" \nFROM employees \nGROUP BY  department_id \nHAVING COUNT(*) &gt; 3;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query2.jpg\"><img decoding=\"async\" width=\"750\" height=\"355\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query2.jpg\" alt=\"sql count - more than 3\" class=\"wp-image-104027\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query2.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query2-300x142.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Departments with employee count more than 3<\/figcaption><\/figure>\n<h3>4.3 Department and employee count<\/h3>\n<p>Let&#8217;s say the business requirement is: We need department names with employee count arranged in decreasing order of employee count. For this requirement, we have to use the DESC keyword.<\/p>\n<pre class=\"brush:sql\">SELECT name Department, COUNT(employee_id) \"No. of employees\"\nFROM employees e INNER JOIN departments d\nON e.department_id = d.department_id\nGROUP BY e.department_id\nORDER BY COUNT(employee_id) DESC;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query3.jpg\"><img decoding=\"async\" width=\"750\" height=\"459\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query3.jpg\" alt=\"sql count\" class=\"wp-image-104028\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query3.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query3-300x184.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Department wise employee count<\/figcaption><\/figure>\n<h3>4.4 Department and manager names<\/h3>\n<p>Suppose management asks that we want a more refined report than the previous one. Instead of <code>department_id<\/code>s, we want department names with department manager names. This requirement needs two <code>JOIN<\/code>s. We need to take two instances of the <code>employees<\/code> table and join each with a separate instance of the <code>departments<\/code> table.<\/p>\n<pre class=\"brush:sql\">SELECT e1.first_name \"Manager first name\", e1.last_name \"Manager last name\", d1.name Department, COUNT(e2.employee_id) \"No. of employees\"\nFROM employees e1 JOIN departments d1 ON e1.department_id = d1.department_id,\nemployees e2 JOIN departments d2 on e2.department_id = d2.department_id\nWHERE d1.department_id = d2.department_id\nAND e1.manager_id IS NULL\nAND e2.manager_id IS NOT NULL\nGROUP BY e1.first_name, e1.last_name, e2.department_id\nORDER BY COUNT(e2.employee_id) DESC;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query4.jpg\"><img decoding=\"async\" width=\"750\" height=\"241\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query4.jpg\" alt=\"sql count\" class=\"wp-image-104029\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query4.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query4-300x96.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Department &amp; manager names with employee count<\/figcaption><\/figure>\n<h3>4.5 Zero-sale months<\/h3>\n<p>Let&#8217;s say we are asked to find out, for each book, how many months were there with no sales? For this case, the required rows can be retrieved by checking if <code>quantity<\/code> is zero.<\/p>\n<pre class=\"brush:sql\">SELECT book_id, COUNT(quantity) \"Zero sales months\"\nFROM book_sales\nWHERE quantity = 0\nGROUP BY book_id;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query5.jpg\"><img decoding=\"async\" width=\"750\" height=\"579\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query5.jpg\" alt=\"sql count\" class=\"wp-image-104030\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query5.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query5-300x232.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Book zero sales months<\/figcaption><\/figure>\n<h3>4.6 Monthly sales<\/h3>\n<p>Suppose we are asked to report in each month, how many of the six books were sold and what are the total copies sold in that month. We combine <code>COUNT<\/code> with <code>SUM<\/code> aggregate function.<\/p>\n<pre class=\"brush:sql\">SELECT month Month, COUNT(quantity) \"Num books sold\", SUM(quantity) \"Monthly sales\"\nFROM book_sales\nWHERE quantity &gt; 0\nGROUP BY month;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query6.jpg\"><img decoding=\"async\" width=\"750\" height=\"712\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query6.jpg\" alt=\"sql count\" class=\"wp-image-104032\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query6.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query6-300x285.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Book monthly sales<\/figcaption><\/figure>\n<h3>4.7 Months in which books were sold and annual sales<\/h3>\n<p>If the management tells us they want to know for each book, the number of months in which sales happened and its annual sales reported with book title in decreasing order of sales. For this requirement, we combine <code>COUNT(*)<\/code> with <code>SUM<\/code> and use <code>DESC<\/code>.<\/p>\n<pre class=\"brush:sql\">SELECT title Title, COUNT(*) \"Sale months\", SUM(quantity) \"Annual sales\"\nFROM book_sales bs JOIN books b ON b.book_id = bs.book_id\nWHERE quantity &gt; 0 \nGROUP BY b.book_id\nORDER BY SUM(quantity) DESC;<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query7.jpg\"><img decoding=\"async\" width=\"750\" height=\"331\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query7.jpg\" alt=\"\" class=\"wp-image-104033\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query7.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query7-300x132.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Books sale-months and annual sales<\/figcaption><\/figure>\n<h3>4.8 Last quarter sales<\/h3>\n<p>Let&#8217;s say the requirement is to get sales for the last quarter only. To get the groups for the last quarter of the year, we need to use the filter <code>month<\/code> greater than 9.<\/p>\n<pre class=\"brush:sql\">SELECT month Month, title Title, SUM(quantity) \"Monthly sales\"\nFROM book_sales bs JOIN books b ON b.book_id = bs.book_id\nGROUP BY month, title\nHAVING month &gt; 9\nORDER BY month, SUM(quantity) DESC<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query8.jpg\"><img decoding=\"async\" width=\"750\" height=\"714\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query8.jpg\" alt=\"\" class=\"wp-image-104044\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query8.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/query8-300x286.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption>Book sales in last quarter<\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\">5. Download the Source Code<\/h2>\n<p>This article was a tutorial on various use cases of the SQL COUNT function. The <code>SQL<\/code> source code for creating the tables, inserting the sample data, and all queries discussed in this article are available in a zip file. <\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/sql-count.zip\"><strong>SQL Count Function<\/strong><\/a><\/div>\n<p><strong>Last updated on Feb. 24th, 2022<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and HAVING. 1. Introduction Many times, the information we want from a database table is not available in a single row but in a group of rows or &hellip;<\/p>\n","protected":false},"author":141,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[189,1055],"class_list":["post-104012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-core-java-2","tag-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Count Function - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Count Function - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-04T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-24T10:09:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mahboob Hussain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mahboob Hussain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\"},\"author\":{\"name\":\"Mahboob Hussain\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7fcaa707830cfea8c55d4ad2b81cbf55\"},\"headline\":\"SQL Count Function\",\"datePublished\":\"2021-08-04T08:00:00+00:00\",\"dateModified\":\"2022-02-24T10:09:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\"},\"wordCount\":1028,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"core java\",\"sql\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\",\"name\":\"SQL Count Function - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2021-08-04T08:00:00+00:00\",\"dateModified\":\"2022-02-24T10:09:55+00:00\",\"description\":\"In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL Count Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7fcaa707830cfea8c55d4ad2b81cbf55\",\"name\":\"Mahboob Hussain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mahboob-Hussain_avatar_1510827107-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mahboob-Hussain_avatar_1510827107-96x96.jpg\",\"caption\":\"Mahboob Hussain\"},\"description\":\"Mahboob Hussain graduated in Engineering from NIT Nagpur, India and has an MBA from Webster University, USA. He has executed roles in various aspects of software development and technical governance. He started with FORTRAN and has programmed in a variety of languages in his career, the mainstay of which has been Java. He is an associate editor in our team and has his personal homepage at http:\/\/bit.ly\/mahboob\",\"sameAs\":[\"http:\/\/bit.ly\/mahboob\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mahboob-hussain\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Count Function - Java Code Geeks","description":"In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/","og_locale":"en_US","og_type":"article","og_title":"SQL Count Function - Java Code Geeks","og_description":"In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and","og_url":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-08-04T08:00:00+00:00","article_modified_time":"2022-02-24T10:09:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Mahboob Hussain","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mahboob Hussain","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/"},"author":{"name":"Mahboob Hussain","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7fcaa707830cfea8c55d4ad2b81cbf55"},"headline":"SQL Count Function","datePublished":"2021-08-04T08:00:00+00:00","dateModified":"2022-02-24T10:09:55+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/"},"wordCount":1028,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["core java","sql"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/sql-count-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/","url":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/","name":"SQL Count Function - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2021-08-04T08:00:00+00:00","dateModified":"2022-02-24T10:09:55+00:00","description":"In this article, we will discuss the COUNT function in SQL, different ways of using it, and how to combine it with other keywords like GROUP BY and","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/sql-count-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/sql-count-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL Count Function"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7fcaa707830cfea8c55d4ad2b81cbf55","name":"Mahboob Hussain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mahboob-Hussain_avatar_1510827107-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mahboob-Hussain_avatar_1510827107-96x96.jpg","caption":"Mahboob Hussain"},"description":"Mahboob Hussain graduated in Engineering from NIT Nagpur, India and has an MBA from Webster University, USA. He has executed roles in various aspects of software development and technical governance. He started with FORTRAN and has programmed in a variety of languages in his career, the mainstay of which has been Java. He is an associate editor in our team and has his personal homepage at http:\/\/bit.ly\/mahboob","sameAs":["http:\/\/bit.ly\/mahboob"],"url":"https:\/\/examples.javacodegeeks.com\/author\/mahboob-hussain\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=104012"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104012\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=104012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=104012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=104012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}