linux mysql _DML_DQL

上篇我们简单介绍了mysql和DDL数据定义语言,现在来介绍一下DML数据操纵语言和DQL数据查询语言

DML 数据操纵语言

DML数据操纵语言分为三大部分
1 插入数据 insert
插入数据的命令:
insert into table1 values(1,’bai’); 完全插入命令 需要对table1表中的每个字段都进行插入
insert into table1(id)values(1); 部分插入 对table1表中的id字段插入一行记录。
2 更新数据 update
Update t1 set id=2 where name=’zhang’ 更新t1表中的数据 把名字叫zhang的一行记录的id改为2
3 删除数据 delete
Delete from t1 where id=2; 删除t1表中id为2的数据;

DQL 数据查询语言

查询需要有一张表才能体现出来 这里我使用一个数据库来进行查询操作下面是employee5表的结构和内容
在这里插入图片描述
图1(表结构)、

在这里插入图片描述

图2 (表内容)

1 简单查询
select * from employee5; 查询employee5表中的所有数据
select id ,name,sex from employee5; 查询employee5表中的id,name,sex字段
2 条件查询
单条件查询 where 方式
select name from employee5 where post=‘hr’; 查询employee5表中职位是hr的人并显示出名字

多条件查询 AND/OR
select name from employee5 where post=‘hr’ and salary=6000; 查询表中职位为hr的人并且工资为6000的人,并显示出名字
select name from employee5 where post=‘hr’ or salary=8000;查询表中职位为hr的人或者工资为8000的人,并显示出名字

BEseTWEEN AND 在某某之间
select name,salary from employee5 where salary between 660 and 8000; 查询表中工资在660到8000之间的人并以名字和工资显示,

IN 集合查询
select name,salary from employee5 where salary in(660,8000,5000,2200); 查询表中工资为660,8000,5000,和2000的人

IS NULL
select name,job_description from employee5 where job_description is null; 查询表中
job_description为空的人
select name,job_description from employee5 where job_description is not null; 不为空

LIKE 模糊查询
select * from employee5 where name like’g%’; 查询表中name以g开头的人,
select * from employee5 where name like’a_’;查询表中以a开头以任意字符结尾的人,
3 查询排序
select name,salary from employee5 order by salary asc; 以salary字段升序排序,asc可以省略
select name,salary from employee5 order by salary desc; 以salary字段降序排序,
select name,salary from employee5 order by salary limit 3; 查看工资最低的三个人

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值