热线电话:13121318867

登录
2020-12-20 阅读量: 570
sql多表连接

1.stu表和sc表做连接:

select * from stu left join sc on stu.s_id=sc.s_id;


2.stu表和sc表和co表做连接:

select * from stu left join sc on stu.s_id=sc.s_id left join co on sc.c_id=co.c_id;


3.将四表做连接:

select * from stu left join sc on stu.s_id=sc.s_id left join co on sc.c_id=co.c_id

left join te on co.t_id=te.t_id;


4.将四表做连接,删除不必要字段:

select stu.*,co.c_id,c_name,score,te.* from stu left join sc on stu.s_id=sc.s_id

left join co on sc.c_id=co.c_id

left join te on co.t_id=te.t_id;


5.stu表和stu表做纵向链接:

select * from stu union select * from stu;


6.stu表和stu表做纵向链接(不自动去重):

select * from stu union all select * from stu;


7.stu表的s_ids_nameco表的c_idc_name做纵向链接:

select s_id,s_name from stu union select c_id,c_name from co;


0.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据