{"id":6041,"date":"2017-07-05T23:27:25","date_gmt":"2017-07-06T06:27:25","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=6041"},"modified":"2024-01-05T20:20:03","modified_gmt":"2024-01-06T03:20:03","slug":"mysql-row-count","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/","title":{"rendered":"MySQL Row Count: How to Get Row Count in MySQL"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn various ways to get MySQL row count in the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting MySQL row count of a single table<\/h2>\n\n\n\n<p>To get the row count of a single table, you use the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-aggregate-functions\/mysql-count\/\">COUNT(*)<\/a><\/code> in a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\"><code>SELECT<\/code><\/a> statement as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-keyword\">COUNT<\/span>(*)\n<span class=\"hljs-keyword\">FROM<\/span>\n    table_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example, to get the number of rows in the <code>customers<\/code> table in the <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>, you use the following statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-keyword\">COUNT<\/span>(*)\n<span class=\"hljs-keyword\">FROM<\/span>\n    customers;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+----------+\n| COUNT(*) |\n+----------+\n|      <span class=\"hljs-number\">122<\/span> |\n+----------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.01 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Getting MySQL row count of two or more tables<\/h2>\n\n\n\n<p>To get the row count of multiple tables, you use the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-union\/\"><code>UNION<\/code><\/a> operator to combine result sets returned by each individual <code>SELECT<\/code> statement.<\/p>\n\n\n\n<p>For example, to get the row count of <code>customers<\/code> and <code>orders<\/code> tables in a single query, you use the following statement.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-string\">'customers'<\/span> tablename, \n     <span class=\"hljs-keyword\">COUNT<\/span>(*) <span class=\"hljs-keyword\">rows<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n    customers \n<span class=\"hljs-keyword\">UNION<\/span> \n<span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-string\">'orders'<\/span> tablename, \n     <span class=\"hljs-keyword\">COUNT<\/span>(*) <span class=\"hljs-keyword\">rows<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+-----------+------+\n| tablename | rows |\n+-----------+------+\n| customers |  <span class=\"hljs-number\">122<\/span> |\n| orders    |  <span class=\"hljs-number\">326<\/span> |\n+-----------+------+\n<span class=\"hljs-number\">2<\/span> rows <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.01 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Getting MySQL row count of all tables in a specific database<\/h2>\n\n\n\n<p>To get the row count of all tables in a specific database e.g., <code>classicmodels<\/code>, you use the following steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, get all table names in the database<\/li>\n\n\n\n<li>Second, construct an SQL statement that includes all <code>SELECT COUNT(*) FROM table_name<\/code> statements for all tables separated by <code>UNION<\/code>.<\/li>\n\n\n\n<li>Third, execute the SQL statement using a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-prepared-statement\/\">prepared statement<\/a>.<\/li>\n<\/ol>\n\n\n\n<p>First, to get all table names of a database, you query from the <code>information_schema<\/code> database as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    table_name\n<span class=\"hljs-keyword\">FROM<\/span>\n    information_schema.tables\n<span class=\"hljs-keyword\">WHERE<\/span>\n    table_schema = <span class=\"hljs-string\">'classicmodels'<\/span>\n        <span class=\"hljs-keyword\">AND<\/span> table_type = <span class=\"hljs-string\">'BASE TABLE'<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+--------------+\n| TABLE_NAME   |\n+--------------+\n| customers    |\n| employees    |\n| offices      |\n| orderdetails |\n| orders       |\n| payments     |\n| productlines |\n| products     |\n+--------------+\n<span class=\"hljs-number\">8<\/span> rows <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.02 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, to construct the SQL statement, we use the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-group_concat\/\"><code>GROUP_CONCAT<\/code> <\/a>and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-concat\/\"><code>CONCAT<\/code> <\/a>functions as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-keyword\">GROUP_CONCAT<\/span>(<span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-string\">'SELECT \\'',\n                        table_name,\n                        '<\/span>\\<span class=\"hljs-string\">' table_name,COUNT(*) rows FROM '<\/span>,\n                        table_name)\n                SEPARATOR <span class=\"hljs-string\">' UNION '<\/span>),\n            <span class=\"hljs-string\">' ORDER BY table_name'<\/span>)\n<span class=\"hljs-keyword\">INTO<\/span> @<span class=\"hljs-keyword\">sql<\/span> \n<span class=\"hljs-keyword\">FROM<\/span>\n    table_list;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this query, <code>table_list<\/code> is a list of table names which is the result of the query in the first step.<\/p>\n\n\n\n<p>The following query uses the first query as a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-derived-table\/\">derived table<\/a> and returns an SQL statement as a string.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-keyword\">GROUP_CONCAT<\/span>(<span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-string\">'SELECT \\'',\n                        table_name,\n                        '<\/span>\\<span class=\"hljs-string\">' table_name,COUNT(*) rows FROM '<\/span>,\n                        table_name)\n                SEPARATOR <span class=\"hljs-string\">' UNION '<\/span>),\n            <span class=\"hljs-string\">' ORDER BY table_name'<\/span>)\n<span class=\"hljs-keyword\">INTO<\/span> @<span class=\"hljs-keyword\">sql<\/span> \n<span class=\"hljs-keyword\">FROM<\/span>\n    (<span class=\"hljs-keyword\">SELECT<\/span> \n        table_name\n    <span class=\"hljs-keyword\">FROM<\/span>\n        information_schema.tables\n    <span class=\"hljs-keyword\">WHERE<\/span>\n        table_schema = <span class=\"hljs-string\">'classicmodels'<\/span>\n            <span class=\"hljs-keyword\">AND<\/span> table_type = <span class=\"hljs-string\">'BASE TABLE'<\/span>) table_list\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you are using MySQL 8.0+, you can use a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-cte\/\">MySQL CTE<\/a> (common table expression) instead of a derived table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">WITH<\/span> table_list <span class=\"hljs-keyword\">AS<\/span> (\n<span class=\"hljs-keyword\">SELECT<\/span>\n    table_name\n  <span class=\"hljs-keyword\">FROM<\/span> information_schema.tables \n  <span class=\"hljs-keyword\">WHERE<\/span> table_schema = <span class=\"hljs-string\">'classicmodels'<\/span> <span class=\"hljs-keyword\">AND<\/span>\n        table_type = <span class=\"hljs-string\">'BASE TABLE'<\/span>\n) \n<span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">CONCAT<\/span>(\n            <span class=\"hljs-keyword\">GROUP_CONCAT<\/span>(<span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-string\">\"SELECT '\"<\/span>,table_name,<span class=\"hljs-string\">\"' table_name,COUNT(*) rows FROM \"<\/span>,table_name) SEPARATOR <span class=\"hljs-string\">\" UNION \"<\/span>),\n            <span class=\"hljs-string\">' ORDER BY table_name'<\/span>\n        )\n<span class=\"hljs-keyword\">INTO<\/span> @<span class=\"hljs-keyword\">sql<\/span>\n<span class=\"hljs-keyword\">FROM<\/span> table_list; \n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, you execute the <code>@sql<\/code> statement using the&nbsp;<a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-prepared-statement\/\">prepared statement<\/a> as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">PREPARE<\/span> s <span class=\"hljs-keyword\">FROM<\/span>  @<span class=\"hljs-keyword\">sql<\/span>;\n<span class=\"hljs-keyword\">EXECUTE<\/span> s;\n<span class=\"hljs-keyword\">DEALLOCATE<\/span> <span class=\"hljs-keyword\">PREPARE<\/span> s;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"162\" height=\"179\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count-Example.png\" alt=\"MySQL Row Count Example\" class=\"wp-image-6042\" title=\"MySQL Row Count Example\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Getting MySQL row count of all tables in a database with one query<\/h2>\n\n\n\n<p>A quick way to get the row count of all tables in a database is by querying data from the <code>information_schema<\/code> database directly:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    table_name, \n    table_rows\n<span class=\"hljs-keyword\">FROM<\/span>\n    information_schema.tables\n<span class=\"hljs-keyword\">WHERE<\/span>\n    table_schema = <span class=\"hljs-string\">'classicmodels'<\/span>\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> table_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"190\" height=\"181\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count.png\" alt=\"MySQL Row Count\" class=\"wp-image-6043\" title=\"MySQL Row Count\"\/><\/figure>\n\n\n\n<p>This method is sometimes not accurate because the row count in the information_schema and\u00a0the actual row count in the tables are not synchronized. <\/p>\n\n\n\n<p>To avoid it, you have to run the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-analyze-table\/\">ANALYZE TABLE<\/a><\/code> statement before querying the row count from <code>information_schema<\/code> database.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ANALYZE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name, ...;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this tutorial, you have learned various ways to get the row count of one or more tables in the MySQL database.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"6041\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/\"\n\t\t\t\tdata-post-title=\"MySQL Row Count: How to Get Row Count in MySQL\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"6041\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/\"\n\t\t\t\tdata-post-title=\"MySQL Row Count: How to Get Row Count in MySQL\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you various ways to get MySQL row count in the MySQL database.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":90,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6041","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL Row Count: How to Get Row Count in MySQL<\/title>\n<meta name=\"description\" content=\"This tutorial shows you various ways to get the MySQL row count of one or more tables in a MySQL database.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Row Count: How to Get Row Count in MySQL\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you various ways to get the MySQL row count of one or more tables in a MySQL database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-06T03:20:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count-Example.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/\",\"name\":\"MySQL Row Count: How to Get Row Count in MySQL\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/MySQL-Row-Count-Example.png\",\"datePublished\":\"2017-07-06T06:27:25+00:00\",\"dateModified\":\"2024-01-06T03:20:03+00:00\",\"description\":\"This tutorial shows you various ways to get the MySQL row count of one or more tables in a MySQL database.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/MySQL-Row-Count-Example.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/MySQL-Row-Count-Example.png\",\"width\":162,\"height\":179,\"caption\":\"MySQL Row Count Example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-row-count\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Basics\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL Row Count: How to Get Row Count in MySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Row Count: How to Get Row Count in MySQL","description":"This tutorial shows you various ways to get the MySQL row count of one or more tables in a MySQL database.","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:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Row Count: How to Get Row Count in MySQL","og_description":"This tutorial shows you various ways to get the MySQL row count of one or more tables in a MySQL database.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-06T03:20:03+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count-Example.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/","url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/","name":"MySQL Row Count: How to Get Row Count in MySQL","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count-Example.png","datePublished":"2017-07-06T06:27:25+00:00","dateModified":"2024-01-06T03:20:03+00:00","description":"This tutorial shows you various ways to get the MySQL row count of one or more tables in a MySQL database.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count-Example.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2017\/07\/MySQL-Row-Count-Example.png","width":162,"height":179,"caption":"MySQL Row Count Example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-row-count\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Basics","item":"https:\/\/www.mysqltutorial.org\/mysql-basics\/"},{"@type":"ListItem","position":3,"name":"MySQL Row Count: How to Get Row Count in MySQL"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=6041"}],"version-history":[{"count":3,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6041\/revisions"}],"predecessor-version":[{"id":14304,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6041\/revisions\/14304"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/174"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=6041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}