In MySQL, you can retrieve the count of rows from multiple tables using subqueries. Subqueries allow you to execute multiple queries within a single statement.
To select the COUNT(*) for each table, create a subquery for each table, as shown below:
<code class="sql">SELECT (SELECT COUNT(*) FROM table1 WHERE someCondition) AS table1Count, (SELECT COUNT(*) FROM table2 WHERE someCondition) AS table2Count, (SELECT COUNT(*) FROM table3 WHERE someCondition) AS table3Count</code>
This query performs the following steps:
The output of the query will be a table with three columns, each representing the count of rows from a specific table. For example, the following output shows the count of rows from three tables:
+-------------+-------------+-------------+ | table1Count | table2Count | table3Count | +-------------+-------------+-------------+ | 14 | 27 | 0 | +-------------+-------------+-------------+
The above is the detailed content of How to Retrieve COUNT(*) Values from Multiple Tables in MySQL?. For more information, please follow other related articles on the PHP Chinese website!