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;