首页 > 数据库技术 > 详细

MySQL基本查询

时间:2019-07-27 19:55:22      阅读:115      评论:0      收藏:0      [点我收藏+]

1、查询某数据库中表的总数

select count(*) from information_schema.tables where table_schema=dbname;

2、仅占一列显示某数据库中的所有表名

select group_concat(table_name) from information_schema.tables where table_schema=‘dbname’;

3、查询某表中有几行

select count(*) from information_schema.COLUMNS where table_schema = dbname AND table_name = tablename;

 4、仅占一列显示某表中的所有字段名

select group_concat(COLUMN_NAME) from information_schema.COLUMNS where table_name = tablename;

 5、查询第一行记录

select  *  from  ‘tablename‘ limit 1;

6、查询第n行到第m行记录

select * from ‘tablename‘ limit m,n;(n<=m)

7、查询第n行记录

select * from ‘tablename‘ limit n-1,1;

8、查询前n行记录

 -- 方法一
 select * from ‘tablename‘ limit 0,n;
 -- 方法二
 select * from ‘tablename‘ limit n;

9、查询后n行记录

-- 倒序排序,取前n行 id为自增形式
select * from ‘tablename‘ order by id desc dlimit n;

10、查询一条记录($id)的下一条记录

select * from ‘tablename‘ where id>$id  order by id asc dlimit 1

11、查询一条记录($id)的上一条记录

select * from ‘tablename‘ where id<$id  order by id desc dlimit 1

 

MySQL基本查询

原文:https://www.cnblogs.com/soldierback/p/11255852.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!