码迷,mamicode.com
首页 > 数据库 > 详细

mysql获取表中数据行数

时间:2018-01-16 18:30:30      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:row   class   com   order   sel   border   查询   alt   info   

获取单个表的行数

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

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

执行结果

技术分享图片

获取两个表的行数

使用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;

运行结果

技术分享图片

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

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;

运行结果

技术分享图片

 

mysql获取表中数据行数

标签:row   class   com   order   sel   border   查询   alt   info   

原文地址:https://www.cnblogs.com/wangzhisdu/p/8297063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!