SQL join关键字

来源:互联网 发布:双色球组合数据 编辑:程序博客网 时间:2024/06/14 18:48

如果一张表有很多个字段可能填入起来十分的困难复杂,不如把它拆分成两个表,然后查看的时候合并起来。

比如我要记录学生的姓名,班级,成绩,父母的电话号码,那么我们可以创建一个表1 储存学生的姓名班级成绩,表二储存学生的父母的电话号码
首先表1 叫student

create table student(    name varchar(20),    class varchar(20),    grade double);

然后数据什么的自己随便填点吧,方便测试。我这里就用现成的数据了。
这是填完之后的样子

接下来我们创建表2 叫parent_information

CREATE TABLE parent_information (    name VARCHAR(20),    father_tel VARCHAR(20),    mather_tel VARCHAR(20));

然后我们select 一下

如果领导要求我们汇总一下表的话我们直接join一下就行

SELECT     student.name,    student.class,    parent_information.father_tel,    parent_information.mather_tel,    student.gradeFROM    student inner        JOIN    parent_information ON student.name = parent_information.mather_tel;

需要注意的是,select并不会对本身表的结构发生改变。

0 0
原创粉丝点击