0
点赞
收藏
分享

微信扫一扫

mysql获取表中数据行数

快乐与微笑的淘气 2022-03-19 阅读 95
MYSQL

获取单个表的行数

使用count(*)或者count(1)

1 SELECT
2     count(1) AS count
3 FROM
4     table_name;

示例:

select count(1) AS count from test_adas_header

执行结果:

获取两个表的行数

使用union组合每个select查询的结果集

例如,要在单个查询中获取customersorders表的行数

 1 SELECT 
 2     'customers' tablename, 
 3      COUNT(1) rows
 4 FROM
 5     customers 
 6 UNION 
 7 SELECT 
 8     'orders' tablename, 
 9      COUNT(1) rows
10 FROM
11     orders;

示例:

SELECT  'test_adas_header' tablename,  COUNT(1) rows  FROM test_adas_header  UNION SELECT 'event_test' tablename,  COUNT(1) rows   FROM event_test;

获取数据库中所有表的行数

1 SELECT 
2     table_name, 
3     table_rows
4 FROM
5     information_schema.tables
6 WHERE
7     table_schema = 'dbname'
8 ORDER BY table_rows desc;

运行结果

举报

相关推荐

0 条评论