我需要两个表来查询数据,如下所示:
EMPLOYEE (FNAME,MINIT,LNAME,SSN(PK),ADDRESS,DEPARTMENTNUM(FK-DEPARTMENT))
DEPARTMENT (DNAME,DEPARTMENTNUM(PK))
我需要使用DEPARTMENT TABLE中的DNAME查找FNAME,MINIT,LNAME。
另外,我想知道如何将三者(FNAME,MINIT,LNAME)合并为简单的NAME。
谢谢
答案 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>