I have to join two tables. But in one table primary key is not there,composite primary key is there,means three columns put together uniquely define a row of that table. I have those three columns in the other table too.rest nothing is common. Is there any way to join these two tables.please explain with the help of example
我必须加入两张桌子。但是在一个表中主键不存在,复合主键存在,意味着三列放在一起唯一地定义该表的一行。我在另一张表中也有这三列。没有什么是常见的。有没有办法加入这两个表。请在示例的帮助下解释
1 个解决方案
#1
18
You can use AND in the expression for the ON criteria and demand the fields are all equal there.
您可以在表达式中使用AND作为ON条件,并要求字段在那里都相等。
SELECT *
FROM Table1
INNER JOIN Table2
ON Table1.Key1 = Table2.Key1 AND Table1.Key2 = Table2.Key2 AND Table1.Key3 = Table2.Key3
#1
18
You can use AND in the expression for the ON criteria and demand the fields are all equal there.
您可以在表达式中使用AND作为ON条件,并要求字段在那里都相等。
SELECT *
FROM Table1
INNER JOIN Table2
ON Table1.Key1 = Table2.Key1 AND Table1.Key2 = Table2.Key2 AND Table1.Key3 = Table2.Key3