将两个具有不同数据类型的表连接在一起?

时间:2014-10-29 16:47:57

标签: sql oracle

例如,当我们使用join

时,通常有2个表员工和部门

enter image description here Employees.Employee_id

|Employees.Dept_id|Departments.Dept_id|Departments.Department_name|Departments.location_id|
           x           x                      x                       x
           x           x                      x                       x
          x            x                      x                       x

在这种情况下查询是什么。 第一个是

SELECT Employees.Employee_id,
  Employees.Dept_id,
  Departments.Dept_id,
  Departments.Department_name,
  Departments.location_id
FROM employees
FULL OUTER JOIN departments
ON Employees.Dept_id=Departments.Dept_id

第二个是什么??? Employees.Employee_id

|Employees.Dept_id|Departments.Dept_id|Departments.Department_name|Departments.location_id|
 X                X
 x                x
 x                x
                                       x                  x          x
                                       x                  x          x
                                       x                  x          x

1 个答案:

答案 0 :(得分:0)

在评论中,您描述的是非联合联盟。像这样:

SELECT Employees.Employee_id,  Employees.Dept_id, NULL, NULL, NULL
FROM employees

UNION ALL

SELECT NULL, NULL,  Departments.Dept_id,  Departments.Department_name,  Departments.location_id
FROM departments
相关问题