union合并表与内连接

union合并表

union合并两个表的学生信息,消除重复项

select *from student
union select *from student02

union all 合并两个表的学生信息,不消除重复项

select *from student
union all select *from student02

将两张表合并的结果集插入在一张新表中

select name,age,sex,address into student_union
from student union all select name,age,sex,address from student02

inner join内连接的使用

创建学生成绩表

create table grade
(
ksid int not null,
csid int not null,
fs int
)
go

向学生成绩表插入信息(学生ID,测试ID,分数)

insert into grade(ksid,csid,fs)values
('7','71','70'),
('8','81','80'),
('9','91','90'),
('13','913','101')
go

查询学生成绩表

select * from grade

两表(学生信息表和学生成绩表)内连接,查询学生信息及成绩

select st.name,st.age,st.sex,st.address,gr.fs
from student st
inner join grade gr
on st.id = gr.ksid

创建学生课程表

create table course
(
kcid int not null,
kcmc char(8)
)
go

向课程表插入信息(课程ID,课程名字)

insert into course(kcid,kcmc) values
('7','语文'),
('8','计算机'),
('9','数学'),
('13','外语')
go

查询学生课程表

select *from course

内连接查询三张表(学生信息表,成绩表,和课程表)

select st.name,gr.fs,co.kcmc
from student st
inner join grade gr on st.id = gr.ksid
inner join course co on gr.ksid = co.kcid
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

走到无路可退

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值