{"id":8404,"date":"2021-01-26T04:34:00","date_gmt":"2021-01-26T04:34:00","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=8404"},"modified":"2026-01-22T04:58:38","modified_gmt":"2026-01-22T04:58:38","slug":"mysql-query-to-get-top-selling-products","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/","title":{"rendered":"How To Get Top Selling Products in MySQL"},"content":{"rendered":"\n<p>It is important to know sales numbers best selling products, if you run an online store or ecommerce business. Since most online websites run on MySQL, in this article, we will look at MySQL Query to get top selling products for your business. It s very useful in understanding which products are doing well, and which ones need a push. You can use these queries to get highest sold products or get a list of best selling items on your site.<\/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\/mysql-query-to-get-top-selling-products\/#MySQL_Query_To_Get_Top_Selling_Products\" >MySQL Query To Get Top Selling Products<\/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\/mysql-query-to-get-top-selling-products\/#How_to_get_best_selling_products\" >How to get best selling products<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#Top_selling_products_by_total_sales\" >Top selling products by total sales<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#Top_Products_by_Total_Sales_Volume\" >Top Products by Total Sales Volume<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#Best_Sellers_by_total_sales\" >Best Sellers by total sales<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#Top_sellers_by_total_volume\" >Top sellers by total volume<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#Get_Product_Sales_using_Ubiq\" >Get Product Sales using Ubiq<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"MySQL_Query_To_Get_Top_Selling_Products\"><\/span>MySQL Query To Get Top Selling Products<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We will look at two cases &#8211; first, when your product information and sales information are in same table. Second, when your product and sales information are in different tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_get_best_selling_products\"><\/span>How to get best selling products<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you have a table <em>sales(id, product, order_date, amount)<\/em> which contains information of product and sale amount in a single table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; create table sales(id int, \n        product varchar(10), \n        order_date date, \n        amount int);\n\nmysql&gt; insert into sales(id, product, order_date, amount)\n       values(1, 'Bike','2021-01-01',150),\n       (2, 'Car','2021-01-01',450),\n       (3, 'Bicycle','2021-01-02',50),\n       (5, 'Car','2021-01-02',450),\n       (6, 'Bike','2021-01-03',150),\n       (7, 'SUV','2021-01-04',850),\n       (8, 'Bike','2021-01-04',150);\n\nmysql&gt; select * from sales;\n+------+---------+------------+--------+\n| id   | product | order_date | amount |\n+------+---------+------------+--------+\n|    1 | Bike    | 2021-01-01 |    150 |\n|    2 | Car     | 2021-01-01 |    450 |\n|    3 | Bicycle | 2021-01-02 |     50 |\n|    5 | Car     | 2021-01-02 |    450 |\n|    6 | Bike    | 2021-01-03 |    150 |\n|    7 | SUV     | 2021-01-04 |    850 |\n|    8 | Bike    | 2021-01-04 |    150 |\n+------+---------+------------+--------+\n<\/pre>\n\n\n\n<p>We will get top selling product by sales, and by volume.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Top_selling_products_by_total_sales\"><\/span>Top selling products by total sales<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is the SQL query to get top selling products by total sales. In our case, we will select top 3 best selling products by total sales amount.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select product, sum(amount) \n       from sales \n       group by product \n       order by sum(amount) desc \n       limit 3;\n +---------+-------------+\n | product | sum(amount) |\n +---------+-------------+\n | Car     |         900 |\n | SUV     |         850 |\n | Bike    |         450 |\n +---------+-------------+<\/pre>\n\n\n\n<p>Let us look at the above query in detail. We basically <a href=\"https:\/\/www.w3schools.com\/mysql\/mysql_groupby.asp\" target=\"_blank\" rel=\"noreferrer noopener\">GROUP BY<\/a> <em>product<\/em> column and aggregate <em>amount<\/em> column using SUM function.<\/p>\n\n\n\n<p>We further ORDER BY sum(amount) in descending order so that the top selling products are listed at the top. We also use LIMIT 3 clause to select only the top 3 rows of result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Top_Products_by_Total_Sales_Volume\"><\/span>Top Products by Total Sales Volume<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is the SQL query to get top selling products by total volume, that is, count of sales.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select product, count(amount) \n       from sales \n       group by product \n       order by count(amount) \n       desc limit 3;\n +---------+---------------+\n | product | count(amount) |\n +---------+---------------+\n | Bike    |             3 |\n | Car     |             2 |\n | Bicycle |             1 |\n +---------+---------------+<\/pre>\n\n\n\n<p>Now, we will look at second case. Sometimes, product and sales information are present in different tables.<\/p>\n\n\n\n<p>Let us say you have two tables <em>product(id, product_name)<\/em> and <em>sales(id, product_id, order_date, amount)<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; create table product(id int,product_name varchar(10));\n\nmysql&gt; insert into product(id, product_name)\n      value(1,'Bike'),\n      (2,'Car'),\n      (3,'Bicycle'),\n      (4,'SUV');\n\nmysql&gt; select * from product;\n +------+--------------+\n | id   | product_name |\n +------+--------------+\n |    1 | Bike         |\n |    2 | Car          |\n |    3 | Bicycle      |\n |    4 | SUV          |\n +------+--------------+\n\nmysql&gt; create table sales(id int, \n      product_id int, \n      order_date date, \n      amount int);\n\nmysql&gt; insert into sales(id, product_id, order_date, amount)\n      values(1, 1,'2021-01-01',150),\n      (2, 2,'2021-01-01',450),\n      (3, 3,'2021-01-02',50),\n      (5, 2,'2021-01-02',450),\n      (6, 1,'2021-01-03',150),\n      (7, 4,'2021-01-04',850),\n      (8, 1,'2021-01-04',150);\n\nmysql&gt; select * from sales;\n +------+------------+------------+--------+\n | id   | product_id | order_date | amount |\n +------+------------+------------+--------+\n |    1 |          1 | 2021-01-01 |    150 |\n |    2 |          2 | 2021-01-01 |    450 |\n |    3 |          3 | 2021-01-02 |     50 |\n |    5 |          2 | 2021-01-02 |    450 |\n |    6 |          1 | 2021-01-03 |    150 |\n |    7 |          4 | 2021-01-04 |    850 |\n |    8 |          1 | 2021-01-04 |    150 |\n +------+------------+------------+--------+<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Best_Sellers_by_total_sales\"><\/span>Best Sellers by total sales<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is the SQL query to get top selling products by total sales. We will basically join the two tables to get product name and total sales in query result.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select product_name, sum(amount)\n           from sales,product\n           where sales.product_id=product.id\n           group by product_name\n           order by sum(amount) desc\n           limit 3;\n +--------------+-------------+\n | product_name | sum(amount) |\n +--------------+-------------+\n | Car          |         900 |\n | SUV          |         850 |\n | Bike         |         450 |\n +--------------+-------------+<\/pre>\n\n\n\n<p>Let us look at the above query in detail. We SELECT <em>product_name<\/em> and <em>sum(amount)<\/em> columns from <em>product<\/em> and <em>sales<\/em> tables. We join the two tables using <em>product_id<\/em> column from <em>sales<\/em> table and <em>id<\/em> column from <em>product<\/em> table, GROUP BY <em>product<\/em> column and aggregate <em>amount<\/em> column using SUM function.<\/p>\n\n\n\n<p>We further ORDER BY sum(amount) in descending order so that the top selling products are listed at the top. We also use LIMIT 3 clause to select only the top 3 rows of result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Top_sellers_by_total_volume\"><\/span>Top sellers by total volume<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is the SQL query to get top selling products by total volume, that is, count of sales.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select product_name, count(amount)\n           from sales,product\n           where sales.product_id=product.id\n           group by product_name\n           order by count(amount) desc\n           limit 3;\n +--------------+---------------+\n | product_name | count(amount) |\n +--------------+---------------+\n | Bike         |             3 |\n | Car          |             2 |\n | Bicycle      |             1 |\n +--------------+---------------+<\/pre>\n\n\n\n<p>If you want to <a href=\"https:\/\/ubiq.co\/tech-blog\/mysql-select-top-n-rows-per-group\/\">select top N rows per group<\/a>, such as top 2 best selling products, then you need to window function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Get_Product_Sales_using_Ubiq\"><\/span>Get Product Sales using 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 to get top selling products, 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=\"417\" src=\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-product-ubiq.webp?resize=730%2C417&#038;ssl=1\" alt=\"\" class=\"wp-image-8406\"\/><\/figure>\n<\/div>\n\n\n<p>In fact, after you run the query, you can simply click a visualization type to plot the result in a chart.<\/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=\"588\" src=\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-product-ubiq-2-3.webp?resize=730%2C588&#038;ssl=1\" alt=\"\" class=\"wp-image-8407\"\/><\/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\/multiple-counts-with-different-conditions-in-single-mysql-query\/\">How to Get Multiple Counts in Single MySQL Query<\/a><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><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.<\/p>\n","protected":false},"author":1,"featured_media":8409,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324],"tags":[444],"class_list":["post-8404","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-top-selling-products"],"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 Top Selling Products in MySQL - Ubiq BI<\/title>\n<meta name=\"description\" content=\"It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.\" \/>\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\/mysql-query-to-get-top-selling-products\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Get Top Selling Products in MySQL - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/\" \/>\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-26T04:34:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-22T04:58:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-products-mysql.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"665\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\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\\\/mysql-query-to-get-top-selling-products\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How To Get Top Selling Products in MySQL\",\"datePublished\":\"2021-01-26T04:34:00+00:00\",\"dateModified\":\"2026-01-22T04:58:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/\"},\"wordCount\":601,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1\",\"keywords\":[\"top selling products\"],\"articleSection\":[\"MySQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/\",\"name\":\"How To Get Top Selling Products in MySQL - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1\",\"datePublished\":\"2021-01-26T04:34:00+00:00\",\"dateModified\":\"2026-01-22T04:58:38+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1\",\"width\":665,\"height\":300,\"caption\":\"top selling products in mysql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/mysql-query-to-get-top-selling-products\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Get Top Selling Products in MySQL\"}]},{\"@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 Top Selling Products in MySQL - Ubiq BI","description":"It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.","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\/mysql-query-to-get-top-selling-products\/","og_locale":"en_US","og_type":"article","og_title":"How To Get Top Selling Products in MySQL - Ubiq BI","og_description":"It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.","og_url":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2021-01-26T04:34:00+00:00","article_modified_time":"2026-01-22T04:58:38+00:00","og_image":[{"width":665,"height":300,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-products-mysql.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\/mysql-query-to-get-top-selling-products\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How To Get Top Selling Products in MySQL","datePublished":"2021-01-26T04:34:00+00:00","dateModified":"2026-01-22T04:58:38+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/"},"wordCount":601,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1","keywords":["top selling products"],"articleSection":["MySQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/","url":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/","name":"How To Get Top Selling Products in MySQL - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1","datePublished":"2021-01-26T04:34:00+00:00","dateModified":"2026-01-22T04:58:38+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"It is important to get top selling products for every ecommerce business. Here is the MySQL query to get top selling products.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2021\/01\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1","width":665,"height":300,"caption":"top selling products in mysql"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/mysql-query-to-get-top-selling-products\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How To Get Top Selling Products in MySQL"}]},{"@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\/2021\/01\/top-selling-products-mysql.webp?fit=665%2C300&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-2by","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8404","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=8404"}],"version-history":[{"count":4,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8404\/revisions"}],"predecessor-version":[{"id":10397,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/8404\/revisions\/10397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/8409"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=8404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=8404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=8404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}