sql内联接外联接三张表
Here you will learn about joining three tables in sql with example.
在这里,您将通过示例了解有关在sql中联接三个表的信息。
Let us consider three tables Employee, Department and Project. We will see the complete example wherein these 3 tables are joined to produce a result:
让我们考虑雇员,部门和项目三个表。 我们将看到完整的示例,其中将这3个表连接起来以产生结果:
表员工 (Table Employee)
This table records the Id of the Employee which is the primary key, the name of the working Employee, the Department Id of the Department they are working in and the Project they are working for.
此表记录了作为主键的Employee ID,工作Employee的名称,他们正在工作的部门的部门ID以及他们正在工作的项目。
- EId – Primary key which holds Id of the Employee. EId –保留员工ID的主键。
- EName – Name of the Employee. EName –员工名称。
- DId – Department Id of the Department, the Employee is working in. DId –部门的部门ID,员工正在工作。
- PId – Project Id of the project the Employee is working for. PId –员工正在从事的项目的项目ID。
Table creation:
表创建:
CREATE TABLE Employee(EId int primary key, EName varchar(20), DId int, PId int)
INSERT INTO Employee VALUES(1, Ramesh)
INSERT INTO Employee VALUES(2, Somesh)
INSERT INTO Employee VALUES(3, Rajesh)
INSERT INTO Employee VALUES(4, Ram)
INSERT INTO Employee VALUES(5, Ishi)
INSERT INTO Employee VALUES(6, Rekha)
INSERT INTO Employee VALUES(7,Mukesh)
This table looks like:
该表如下所示:
EId | EName | DId | PId |
1 | Ramesh |