我有三张桌子:
tbl_ProjectsUsers
ProjectId
companyUserID
tbl_Projects
ProjectId
CompanyClientId
tbl_CompanyClient
CompanyClientName
CompanyClientId
如何使用@companyUserID从三个表中检索ProjectID,CompanyClientID,CompanyClientName
答案 0 :(得分:2)
您可以在三个表之间进行连接:
SELECT t1.ProjectId,
t1.companyUserID,
COALESCE(t2.CompanyClientId, 'NA'),
COALESCE(t3.CompanyClientName, 'NA')
FROM tbl_ProjectsUsers t1
LEFT JOIN tbl_Projects t2
ON t1.ProjectId = t2.ProjectId
LEFT JOIN tbl_Company_Client t3
ON t2.CompanyClientId = t3.CompanyClientId
WHERE t1.companyUserID = <some_value>
答案 1 :(得分:0)
((MainActivity)context).getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, frag).commit();
答案 2 :(得分:0)
希望这有帮助
以下是您要求的解决方案:
Declare @CompanyUserID int = 10 --no idea what the data type is but i assume an integer.
Select
u.CompanyUserID
, p.ProjectID
, c.CompanyClientID
, c.CompanyClientName
FROM
tbl_ProjectUsers u
JOIN tbl_Projects p on u.ProjectID = p.ProjectID
JOIN tbl_CompanyClient c on p.CompanyClientID = c.CompanyClientID
WHERE
u.CompanyUserIDin (@CompanyUserID)
如果更改变量编号(10),它将返回不同的结果。我假设你把它设置为Int但它可能是一个字符串 如果它是一个类似下面的字符串应该工作
Declare @CompanyUserID varchar(max) = 'UserID'
您需要更具体地确定连接类型,但在T-SQL中,这适用于我。我建议使用更多的内连接或左连接,但是只使用JOIN就足够了
POST注意 - 我看到你更新了帖子,所以现在它对3个表格有意义