我有2张这样的表:
有了这个条件
<style type="text/css">
.tab { margin-left: 40px; }
</style>
echo "<strong> Introduction: </strong>
<p class='tab'>
This is the introduction. This is the introduction. This is the introduction. This is the introduction. This is the introduction. This is the introduction. This is the introduction. This is the introduction. This is the introduction.
</p>";
我想在查询中选择ON dbo.MaterialDescriptions.Id = dbo.Joints.RightMaterialDescriptionId
AND dbo.MaterialDescriptions.Id = dbo.Joints.LeftMaterialDescriptionId
和RightMaterialDescriptionId
的商品代码。我怎么能这样做?
答案 0 :(得分:2)
您需要使用不同的别名将表连接两次:
SELECT rmd.ItemCode as RightItemCode, lmd.ItemCode as LeftItemCode [, other columns...]
FROM dbo.Joints j
JOIN dbo.MaterialDescriptions rmd ON j.RightMaterialDescriptionId = rmd.Id
JOIN dbo.MaterialDescriptions lmd ON j.LeftMaterialDescriptionId = lmd.Id
注意:您可能希望使用LEFT JOIN
代替INNER JOIN