mysql 数据库基础查询操作命令

查询命令集合

- 数据库基础查询
-以单表数据查询所有数据
select * from table; //查询表中所有信息
select id from table;
select id ,name from table; // 查询表中指定的字段查询
- 数据库条件查询
-以某些数据作为条件进行查询符合条件的数据
select * from table where 条件字段=‘需要检索条件’;
select * from table where table.a is null;//查询条件为空的数据
select * from table where table.a > 100 or table.b >30;// 两者条件有一个满足即可
select * from table where table.a >100 and table.b>30;// 两者条件都要满足
- 数据库排序查询
-查询数据信息以什么条件进行排序,升or 降
select * from table where 条件字段=‘需要检索条件’ order by id desc/asc
- 数据库分组查询
select * from table where 条件字段=‘需要检索条件’ group by id
- 数据库分页查询
select * from table where id >10000 limit 1000,10
- 数据库连接查询
– 交叉连接
select * from table_a cross join table_b;
– 内连接
select * from table_a inner join table_b;
select * from table_a inner join table_b on b_id = id;
select * from table_a inner join table_b on table_a.b_id = table_b.id;
select * from table_a as s inner join table_b c on s.b_id = c.id;
select * from table_b c inner join table_a as s on s.b_id = c.id;
select * from table_b c inner join table_a as s where s.b_id = c.id;
select * from table_a as s left join table_b c on s.b_id = c.id;
select * from table_a as s right join table_b as c on s.b_id = c.id;
select * from table_b as c left join table_a as s on s.b_id = c.id;
– 自然内连接
select * from table_a natural join table_b;
– using关键字
select * from table_a left join table_b using(b_id);
- 数据库子查询

  • select* from table_a id in(select id from table_b)// 子查询内的语句同样适用各种查询语句
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值