第七章
1.内连接
内连接语法
select 字段列表 from tab1 [ inner ] join tab2 on tab1.col1=tab2.col2 [where 子句]
2.自然连接
自然连接语法
select 字段列表 from tab1 natural join tab2 [ where 子句 ]
(1)要求连接表的依据列必须是相同的字段
(2)可以去除重复的列
3.多表连接
多表连接语法:
select 字段列表 from tab1 join tab2 on tab1.col1=tab2.col2 join tab3 on tab2.col2=tab3.col3 [where 子句]
(1)用简单多表连接表:
select 字段列表 from tab1,tab2,tab3 where tab1.col1 = tab2.col2 [and tab2.col2=tab3.col3]
4.外连接
外连接语法
select 字段列表 from tab1 left|right|full [outer] join tab2 on tab1.col1 = tab2.col2;
1)外连接,左外连接就是左表完整展示,右表只展示符合条件的字段,不符合的列值为null;右外连接与左外连接相反
练习
1.bus数据库查询
(1)经常出现字段模糊报错,在每个字段前加上表名指向后解决;
(2) 出现重复时尝试使用group by 去重,被老师提醒使用distinct去重才规范
2.easyshopping数据库查询
遇见问题:
1.对代码不熟练
2.写代码时会无从下手
3.记不清代码
总结:
1.多记多练代码
2.多实操