[英]Find Table with maximum number of rows in a database in mysql
As the question title suggests, I want to find the table having maximum number of rows (entries) in a particular database. 正如问题标题所暗示的那样,我想在特定数据库中找到具有最大行数(条目)的表。 I have been able to extract the names of all the tables in a particular database using the query below. 我已经可以使用下面的查询提取特定数据库中所有表的名称。
SELECT TABLE_NAME
FROM information_schema.tables
WHERE TABLE_SCHEMA="Some_Database";
How do I proceed beyond this?? 除此以外,我该如何进行? I have been trying to formulate a nested query for the above purpose but couldn't come up with something (I am not very comfortable with them). 我一直试图为上述目的制定一个嵌套查询,但无法提出一些建议(我对它们不太满意)。 Please Help. 请帮忙。
EDIT: As given in this link the table_rows field does not give an accurate result. 编辑:如此链接中所述,table_rows字段未提供准确的结果。 That is why I need to do something like a MAX (Count(*))
for each table. 这就是为什么我需要对每个表执行类似MAX (Count(*))
的原因。
Try this one...... 试试这个……
SELECT TABLE_NAME,MAX(TABLE_ROWS)
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "DB_Name";
OR 要么
please try the following two queries for actual result. 请尝试以下两个查询以获得实际结果。
query 1: 查询1:
SELECT CONCAT('SELECT COUNT(*) as cnt FROM ', table_name, ' union all')
FROM information_schema.tables WHERE table_schema = 'your_db_name';
query 2: 查询2:
select max(cnt) from (paste the result of first query and remove
last union all keyword) as tmptable;
What about this: 那这个呢:
SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "Some_Database"
ORDER BY TABLE_ROWS DESC
LIMIT 1;
information_schema.tables
has a column named table_rows
, so: information_schema.tables
有一个名为table_rows
的列,因此:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'Some_Database'
ORDER BY table_rows DESC
LIMIT 1;
We can obtain the table name having max number of rows in MySQL using the this query 我们可以使用此查询获取MySQL中具有最大行数的表名
SELECT
TABLE_NAME,MAX(TABLE_ROWS)
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'DB_Name'
GROUP BY TABLE_NAME ORDER BY MAX(TABLE_ROWS) DESC LIMIT 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.