开发者

SQL Inner join 2 tables to 1 question

开发者 https://www.devze.com 2023-03-18 15:55 出处:网络
If I have the following line of code: INN开发者_StackOverflow中文版ER JOIN #CompanyIdT t ON e.[companyId] = t.[Value] AND c.[CompanyId] = t.[Value]

If I have the following line of code:

INN开发者_StackOverflow中文版ER JOIN #CompanyIdT t ON e.[companyId] = t.[Value] AND c.[CompanyId] = t.[Value]

Does this always join to the same companyId in the t table? So could e and c ever have a different CompanyId in 1 record?

Thanks


No, e and c would never have a different value for companyID in a single record in the result set. They will always match t.Value, thus in your resultset it will always be the case that e.companyId = c.companyId = t.Value.


You've described a transitive relationship:

If e.CompanyId = t.Value and c.CompanyId = t.Value, then e.CompanyId = c.CompanyId.

Since that statement is always true, you should never have a different CompanyId in any row in your query results. If you have duplicate Value values in t, you could get multiple rows with the same CompanyId.

0

精彩评论

暂无评论...
验证码 换一张
取 消