[英]How to join the two tables with the same primary key?
如何使用相同的主鍵聯接兩個表?
表格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
表2:
Item_ID Cost
I1 21
I1 54
I1 27
I1 32
I2 65
I2 75
I3 45
I3 46
I4 34
I4 74
請嘗試這個。
SELECT * FROM table1 A
INNER JOIN table2 B
ON A.Item_Id = B.Item_Id
使用聯接 :
SELECT name, date, cost from Table1, Table2 INNER JOIN table2 AS two ON two.item_id=item_id
下次,請在Google上進行搜索。 那里有很多簡單的例子。
請嘗試以下查詢。
您可以通過“ INNER JOIN”聯接表。 t1和t2是表的別名。 因此,您可以讀取相同的列名。
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.