[英]How to join the two tables with the same primary key?
How to join the two tables with the same primary key? 如何使用相同的主键联接两个表?
Table1: 表格1:
Item_ID Name Date
I1 ABC 21-03-2018
I2 EFG 21-04-2018
I3 XYZ 21-05-2018
I4 LKJ 21-06-2018
Table2: 表2:
Item_ID Cost
I1 21
I1 54
I1 27
I1 32
I2 65
I2 75
I3 45
I3 46
I4 34
I4 74
Please try this. 请尝试这个。
SELECT * FROM table1 A
INNER JOIN table2 B
ON A.Item_Id = B.Item_Id
Please try following query. 请尝试以下查询。
You can Join the tables through "INNER JOIN" . 您可以通过“ INNER JOIN”联接表。 t1 & t2 is alias for Tables. t1和t2是表的别名。 So you can read the same column name. 因此,您可以读取相同的列名。
SELECT *
FROM Table1 as t1
INNER JOIN Table2 as t2
ON t1.Item_ID=t2.Item_ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.