您当前的位置: 首页 >  sql

qq_34412985

暂无认证

  • 2浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

mysql 子查询种类及联合查询的sql语句写法

qq_34412985 发布时间:2019-01-05 14:22:51 ,浏览量:2

子查询:

将一个查询语句嵌套在另一个查询语句中,内层查询语句的查询结果可以作为外层查询语句提供条件。

1.in ,not in

2.比较运算符>=

select id,name from student where score >=(select level from scholarship where id=1)

3.[not] exists

select  id,username from employee where exists(select id   from department where id=5)

4.any|some  all配合>=比较运算符

select id,name from student where score >=any(select level from scholarship)

5.将查询结果写入数据表   保证字段顺序,字段数目一致test1的列得存在

insert test1(id,num) select id,score from student;

6.创建数据表同时将查询结果写入到数据表   如果字段名称不一致,以查询出来的为主,原字段为null

create table [if not exists] employee(id,score) select id,score from student;

 

联合查询:

union去掉重复的 union all简单并集   两张表的查询的列数量一样,类型可以不一样

select id from bbs_addr union select name from bbs_brand;  id是BigInt  name是varchar类型

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0485s