SQL语言(DML语句、DQL语句)

DQL

目的:在MySQL管理软件中,通过DDL语言实现数据的查询操作。
简单查询:
查看所有列:前提是需要进入数据库,不进入数据库,使用 数据库.表名 的格式。

select * from 表名;

查看部分列:

select * 列1,列2,列3  from 表名;

条件查询:
简单条件查询where:

select 列名1,列名2 from 表名 where 列名=值;

多条件查询and/or:

select 列1,列2 from 表名 where 列名4=值 and 列名5=值;查询同时满足列名4的值和列名5的值的数据。
select 列名 from 表名 where 条件1 or 条件2;  查询列中符合条件1或条件2的内容。

查询在什么之间的数据between and:

select 列名  from 表名 where 列名 条件1 and 条件2;

查询不在什么之间的数据 not between and:

select 列名 from 表名 where 列名 not between 条件1 and 条件2;

关键字in集合查询:

select  列名  from 表名 where 列名 in(条件1,条件2,条件3);       查询列中符合条件1或条件2或条件3的内容。
select 列名 from 表名 where 列名 not in(条件1,条件2,条件3);     查询列中不符合条件1、条件2、条件3的内容。

关键字is null:

select 列名 from 表名 where 列名 is null;查询指定列中内容是空的数据。

关键字like模糊查询:

select * from 表名 where 列名 like‘a%';   查询列中首字母是a的数据
select * from 表名 where 列名 like ’a_';  在mysql中下划线_代表任一字符

查询排序:

select * from 表名 order by 工资的排名 asc;   升序
select * from 表名 order by 工资的排名 desc; 降序
select * from 表名 order by 列名 desc limit 5; 最高的前五名

DML

目的: DDL定义了数据库结构,实现数据的操作。
插入数据insert:

insert into 表名(列名,列名) values (值1,值2);    部分插入
insert into 表名  values (值1,值2,...值n);   完整插入

更新数据update:

update 表名 set 列名=值 where condition;

删除数据delete:

delete from 表名 where condition;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值