检索在部门工作的员工的姓名和地址

时间:2014-04-04 16:19:50

标签: sql database merge oracle11g

我需要两个表来查询数据,如下所示:

EMPLOYEE (FNAME,MINIT,LNAME,SSN(PK),ADDRESS,DEPARTMENTNUM(FK-DEPARTMENT))
DEPARTMENT (DNAME,DEPARTMENTNUM(PK))

我需要使用DEPARTMENT TABLE中的DNAME查找FNAME,MINIT,LNAME。

另外,我想知道如何将三者(FNAME,MINIT,LNAME)合并为简单的NAME。

谢谢

2 个答案:

答案 0 :(得分:1)

试试这个:

SELECT D.DNAME,E.FNAME+' '+E.MINIT+' '+E.LNAME as NAME
FROM EMPLOYEE E INNER JOIN
DEPARTMENT D ON E.DEPARTMENTNUM=D.DEPARTMENTNUM

答案 1 :(得分:0)

使用CONCAT()函数

select CONCAT(FNAME, " ", MINIT, ".", " ", LNAME) as NAME
FROM EMPLOYEE E INNER JOIN DEPARTMENT D
ON
E.DEPARTMENTNUM = D.DEPARTMENTNUM
AND DNAME = <your-dept>