DQL数据查询语言

本文详细介绍了DQL数据查询语言的基础知识,包括查询单列、多列、带条件的查询、别名设置、多条件组合查询、排序、分页、模糊查询以及去重等操作。通过实例讲解了如何使用DQL有效地查询数据库。
摘要由CSDN通过智能技术生成

DQL数据查询语言

1、DQL:数据查询语言,用来查询表中的数据

2、select 查询 from 从

3、无论怎么对表中的数据进行查询,返回的是一个特定的结果集,不会对表中的数据造成影响的

4、查询单列 select 列名 from 表名;

5、查询多列 select 列名1,列名2… from 表名;

6、查询表中所有的数据 select * from 表名;

7、带条件的查询 where select * from 表名 where 条件

8、给列名设置别名 as as可以省略不写 select 列名 as 别名 from 表名

9、多条件查询 and 多个条件要同时满足 select * from 表名 where 条件1 and 条件2

10、或者 or 多个条件满足一个select * from 表名 where 条件1 or 条件2

11、> < <= >= != <> 不等于 select * from 表名 where age != 18;

12、范围查询 >= and <= 来实现范围查询
between … and … 在 … 和 … 之间
select * from 表名 where age >= 18 and age <= 38;
select * from 表名 where age between 18 and 38;
13、空查询和非空查询 is null is not null

select * from 表名 where hobby is null;
select * from 表名 where hobby is not null;

14、集合查询 在集合中 in() 不在集合中 not in()
查询年龄是18或者38 select * from 表名 where age in(18,38);
查询年龄不是18并且年龄不是38 select * from 表名 where age not in(18,38);

15、排序查询 order by asc 升序 desc 降序 不写默认就是升序
根据年龄进行降序排序:select * from 表名 order by age desc;
如果出现了条件和排序,先进行where对原始数据进行筛选,在对筛选过后的结果集进行排序
where > order by

16、分页查询 limit 限制返回的条数
1、limit count; 查询前count条数据
2、limit index,count; 从索引index开始查询前count数据;

limit 可以实现分页查询 每页显示3条数据
第一页 select * from 表名 limit 0,3;
第二页 select * from 表名 limit 3,3;
第三页 select * from 表名 limit 6,3;
第n页 select * from 表名 limit (n - 1) * 3,3;
如果同时出现条件查询、分页查询、排序查询
where > order by > limit

17、模糊查询 like %匹配任意字符 _匹配任意单个字符
查询姓名包含张的 select * from 表名 where sname like ‘%张%’;

18、去重关键字 distinct 写在 字段名前面
多条件 and
或者 or
空查询 is null is not null
集合查询 in() not in()
符号查询 > < >= <= != <>
范围查询 >= … <= between … and…
排序 order by desc 降序 asc 升序 默认降序
分页查询 limit count index,count;
模糊查询 like % _
去重关键字 distinct

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Programming Life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值