{"id":8410,"date":"2021-01-25T05:48:00","date_gmt":"2021-01-25T05:48:00","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=8410"},"modified":"2025-09-01T05:17:46","modified_gmt":"2025-09-01T05:17:46","slug":"multiple-counts-with-different-conditions-in-single-mysql-query","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/","title":{"rendered":"How to Get Multiple Counts in Single MySQL Query"},"content":{"rendered":"\n<p>MySQL is a popular database used by many organizations to store lots of data. Often database programmers and web developers need to be able to calculate count or sum of multiple columns, each using specific conditions. While it is easy to aggregate columns based on one or more columns, all using the same set of conditions, it can be tricky to do so using different conditions for each column. Nevertheless, you can still get multiple counts with different conditions or criteria in a single query in MySQL, using IF or CASE statements. You will need to use it along with the count() or sum() aggregation function, as per your need. In this article, we will look at how to get multiple counts with multiple conditions in MySQL. Before we proceed, it is important to understand how aggregation functions works, and also a learn a little bit about IF\/CASE statements.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#Count_function_in_MySQL\" >Count() function in MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#If_Statement_in_MySQL\" >If Statement in MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#Case_Statement_in_MySQL\" >Case Statement in MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#How_to_Get_Multiple_Counts_in_single_MySQL_query\" >How to Get Multiple Counts in single MySQL query<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#Get_Multiple_Counts_in_Ubiq\" >Get Multiple Counts in Ubiq<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Count_function_in_MySQL\"><\/span>Count() function in MySQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Count() function is an aggregation function that counts number of rows in a table based on none or one or more conditions. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT COUNT(column_name1), COUNT(column_name2), ...<br>FROM &lt;TABLE_NAME&gt; <br>WHERE &lt;CONDITION&gt;;<\/pre>\n\n\n\n<p>In the above statement, you can see that counts of column1, column2 and so on are all calculated using the same set of conditions. <\/p>\n\n\n\n<p>But how to get counts for where each column has different conditions? That is where IF\/CASE statements are required.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"If_Statement_in_MySQL\"><\/span>If Statement in MySQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.4\/en\/if.html\" target=\"_blank\" rel=\"noreferrer noopener\">If() function<\/a> simply returns one value if a condition is true, and another value if it is false. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">IF(condition, value_if_true, value_if_false)<\/pre>\n\n\n\n<p>Here is a simple example that returns 1 if product column is &#8216;A&#8217;, else it returns null.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if(product='A',1,null)<\/pre>\n\n\n\n<p>Now instead of counting the product column, we can use count() function on the result of this if() function to get a count of values where product=&#8217;A&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">count(if(product='A',1,null)) as A_count<\/pre>\n\n\n\n<p>Similarly, we can define another count where product=&#8217;B&#8221; and amount&gt;200.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">count(if(product='B' and amount&gt;200,1,null)) as B_count<\/pre>\n\n\n\n<p>Now, we can put both the above counts in the same SQL query to calculate two different counts using completely different conditions for each column.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select count(if(product='A',1,null)) as A_count,<br>        count(if(product='B' and amount&gt;200,1,null)) as B_count<br>        from product_sales;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Case_Statement_in_MySQL\"><\/span>Case Statement in MySQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Similarly, you can also use CASE() statement for this purpose. It evaluates several different conditions and returns different values for each condition. It is more versatile than IF statement which allows you to return only 2 values. CASE statement allows you to work with more conditions and results. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CASE<br>    WHEN condition1 THEN result1<br>    WHEN condition2 THEN result2<br>    WHEN conditionN THEN resultN<br>    ELSE result<br>END;<\/pre>\n\n\n\n<p>Here is an example to use CASE statement to get conditionally count product column where product=&#8217;A&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">count(case when product='A' then 1 else null end) as A_count<\/pre>\n\n\n\n<p>Similarly, here is an example to count product column where product=&#8217;B&#8217; and amount&gt;200.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">count(case when product='B' and amount&gt;200 then 1 else null end) as B_count<\/pre>\n\n\n\n<p>Putting the two case statements together in one query, we obtain the following.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select count(case when product='A' then 1 else null end) as A_count,<br>       count(case when product='B' and amount&gt;200 then 1 else null end) as B_count<br>       from product_sales;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Get_Multiple_Counts_in_single_MySQL_query\"><\/span>How to Get Multiple Counts in single MySQL query<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the steps to get multiple counts with different conditions in single MySQL query.<\/p>\n\n\n\n<p>Let us say you have the following table <em>product_sales(id, product, order_date, amount)<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; create table product_sales(\n     id int,\n     product varchar(10),\n     order_date date,\n     amount int\n     );\n\nmysql&gt; insert into product_sales(id, product, order_date, amount)\n     values(1, 'A', '2021-01-01', 250),\n     (2, 'B', '2021-01-02', 200),\n     (3, 'A', '2021-01-03', 150),\n     (4, 'B', '2021-01-04', 250);\n\nmysql&gt; select * from product_sales;\n+------+---------+------------+--------+\n| id   | product | order_date | amount |\n+------+---------+------------+--------+\n|    1 | A       | 2021-01-01 |    250 |\n|    2 | B       | 2021-01-02 |    200 |\n|    3 | A       | 2021-01-03 |    150 |\n|    4 | B       | 2021-01-04 |    250 |\n+------+---------+------------+--------+<\/pre>\n\n\n\n<p>Let us say you want total count, count of product A orders, and count of product B orders with amount &gt; 200 in single query.<\/p>\n\n\n\n<p>Here is the SQL query to accomplish the above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select count(*) as total_count,<br>        count(if(product='A',1,null)) as A_count,<br>        count(if(product='B' and amount&gt;200,1,null)) as B_count<br>        from product_sales;<br>+-------------+---------+---------+<br>| total_count | A_count | B_count |<br>+-------------+---------+---------+<br>|           4 |       2 |       1 |<br>+-------------+---------+---------+<\/pre>\n\n\n\n<p>Let us look at the above query in detail.<\/p>\n\n\n\n<p><em>count(*)<\/em> counts all rows in table to give total count.<\/p>\n\n\n\n<p><em>count(if(product=&#8217;A&#8217;,1,null)) as A_count<\/em> &#8211; when we use an IF condition inside count function, it will only count rows where condition is true. Our condition is to match rows where product = A. So MySQL, counts only those rows where product is A. Else it is not counted (assigned as NULL).<\/p>\n\n\n\n<p>Please note, it is important to use <em>null<\/em> in case IF condition fails else even non-matching rows are counted.<\/p>\n\n\n\n<p>Similarly, we calculate count for rows where product=B and amount &gt; 200.<\/p>\n\n\n\n<p>You can also get above result using CASE statement as shown below.<\/p>\n\n\n\n<pre id=\"block-2faed2ef-4a7b-481d-a4fc-d10a47ece1a1\" class=\"wp-block-preformatted\">mysql&gt; select count(*) as total_count,\n count(case when product='A' then 1 else null end) as A_count,\n count(case when product='B' and amount&gt;200 then 1 else null end) as B_count\n from product_sales;\n+-------------+---------+---------+\n| total_count | A_count | B_count |\n+-------------+---------+---------+\n|           4 |       2 |       1 |\n+-------------+---------+---------+<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt a couple of different ways to aggregate table columns such that each column has different set of conditions. Instead of calling count() function directly on the column names, you need to call it on the result of IF() or CASE() statements. This allows you to mention completely different conditions in each IF\/CASE statement, without using the WHERE clause at all. We have used count() function to do aggregations but you can also use other functions such as SUM(), MIN(), MAX(), etc. as per your requirement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Get_Multiple_Counts_in_Ubiq\"><\/span>Get Multiple Counts in Ubiq<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/\">Ubiq<\/a>&nbsp;Reporting tool supports all the above SQL queries and makes it easy to visualize SQL results in different ways. It also allows you to create dashboards &amp; charts from MySQL data. Here is the SQL query mentioned above, in Ubiq.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"396\" src=\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/multiple-counts-multiple-conditions-mysql.webp?resize=730%2C396&#038;ssl=1\" alt=\"\" class=\"wp-image-8415\"\/><\/figure>\n<\/div>\n\n\n<p>Need a reporting tool for MySQL? <a href=\"http:\/\/ubiq.co\/\">Ubiq<\/a>&nbsp;makes it easy to visualize data in minutes, and monitor in real-time dashboards.&nbsp;<a href=\"http:\/\/ubiq.co\/accounts\/register\">Try it<\/a>&nbsp;Today!<\/p>\n\n\n\n<p>Also read:<br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-write-case-statement-in-mysql\/\">How to Use Case Statement in MySQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-use-coalesce-in-mysql\/\">How to Use Coalesce in MySQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-query-json-column-in-mysql\/\">How to Query JSON Column in MySQL<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts with different criteria in MySQL.<\/p>\n","protected":false},"author":1,"featured_media":8412,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324],"tags":[446,445],"class_list":["post-8410","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-multiple-conditions","tag-multiple-counts"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Get Multiple Counts in Single MySQL Query - Ubiq BI<\/title>\n<meta name=\"description\" content=\"It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts in single query in MySQL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get Multiple Counts in Single MySQL Query - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts in single query in MySQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-25T05:48:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-01T05:17:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"730\" \/>\n\t<meta property=\"og:image:height\" content=\"410\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Get Multiple Counts in Single MySQL Query\",\"datePublished\":\"2021-01-25T05:48:00+00:00\",\"dateModified\":\"2025-09-01T05:17:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/\"},\"wordCount\":816,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1\",\"keywords\":[\"multiple conditions\",\"multiple counts\"],\"articleSection\":[\"MySQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/\",\"name\":\"How to Get Multiple Counts in Single MySQL Query - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1\",\"datePublished\":\"2021-01-25T05:48:00+00:00\",\"dateModified\":\"2025-09-01T05:17:46+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts in single query in MySQL.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1\",\"width\":730,\"height\":410,\"caption\":\"mysql multiple count multiple conditions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/multiple-counts-with-different-conditions-in-single-mysql-query\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get Multiple Counts in Single MySQL Query\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get Multiple Counts in Single MySQL Query - Ubiq BI","description":"It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts in single query in MySQL.","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:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/","og_locale":"en_US","og_type":"article","og_title":"How to Get Multiple Counts in Single MySQL Query - Ubiq BI","og_description":"It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts in single query in MySQL.","og_url":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2021-01-25T05:48:00+00:00","article_modified_time":"2025-09-01T05:17:46+00:00","og_image":[{"width":730,"height":410,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp","type":"image\/webp"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Get Multiple Counts in Single MySQL Query","datePublished":"2021-01-25T05:48:00+00:00","dateModified":"2025-09-01T05:17:46+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/"},"wordCount":816,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1","keywords":["multiple conditions","multiple counts"],"articleSection":["MySQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/","url":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/","name":"How to Get Multiple Counts in Single MySQL Query - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1","datePublished":"2021-01-25T05:48:00+00:00","dateModified":"2025-09-01T05:17:46+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"It is easy to get multiple counts with multiple conditions in MySQL. Here is how to get multiple counts in single query in MySQL.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1","width":730,"height":410,"caption":"mysql multiple count multiple conditions"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/multiple-counts-with-different-conditions-in-single-mysql-query\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Get Multiple Counts in Single MySQL Query"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/06\/mysql-multiple-count-multiple-conditions.webp?fit=730%2C410&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-2bE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=8410"}],"version-history":[{"count":5,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8410\/revisions"}],"predecessor-version":[{"id":9388,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8410\/revisions\/9388"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/8412"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=8410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=8410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=8410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}