SQL从表1中选择*,在表2中使用条件选择几列

时间:2015-07-23 00:50:29

标签: sql-server

R CMD check --help

如何创建一个sql语句,该语句从 familyInfo Table pFnumber pInterviewee pInterviewed personInfo Table pControlNo pLname pFname 表返回有关familyInfo表和pLnamepFname的所有信息,条件为pFnumber = 1且pControlNo = 1

非常感谢帮助

1 个答案:

答案 0 :(得分:0)

SELECT * FROM FAMILYINFO AS F
INNER JOIN PERSONINFO AS P ON F.PFNUMBER = P.PCONTROLNO
WHERE F.PFNUMBER = 1

在阅读评论后编辑为包含左外连接。我相信你说数据可能并不总是在familyinfo中,但你总是会有一个plname记录。

SELECT * FROM PERSONINFO AS P
LEFT OUTER JOIN FAMILYINFO AS F ON P.PCONTROLNO = F.PFNUMBER 
AND F.PFNUMBER = 1