mysql——多表——内连接查询

内连接查询:可以查询两个或者两个以上的表,当两个表中存在表示相同意义的字段时,可以通过该字段来连接这两个表;

                      当该字段的值相等时,就查询出该记录。

 

前期准备两个表:

create table employee ( num int(50),
                        d_id int(50),
                        name varchar(50),
                        age int(50),
                        sex varchar(50),
                        homeadd varchar(50)
                       );

insert into employee values(1,1001,'zhangsan',26,'nan','beijing'); insert into employee values(2,1001,'lisi',24,'nv','hunan'); insert into employee values(3,1002,'wangwu',25,'nan','jiangsu'); insert into employee values(4,1004,'aric',15,'nan','yingguo');

select * from employee;



create table department ( d_id int(50), d_name varchar(50), functione varchar(50), address varchar(50) );
insert into department values(1001,'keyanbu','yanfachanpin','3lou5hao'); insert into department values(1002,'shengchanbu','shengchanchanp','5louyiceng'); insert into department values(1003,'xiaoshoubu','cehuaxiaoshou','1louxiaoshoudating');

select * from department;

mysql——多表——内连接查询

 

 mysql——多表——内连接查询

 

 

 

 

执行查询:

select num,name,employee.d_id,age,sex,d_name,functione from employee,department where employee.d_id = department.d_id;

mysql——多表——内连接查询

上一篇:MySQL随记 - 连接查询


下一篇:Oracle高级子查询