[英]How to merge two tables in SQL?
我有兩個表table1和table2。 兩個表都有多個列。
table1: serialno , recordno....
table2: recodno,issueid....
我想以檢索所有的行table1
, issueid
從table2
與條件table1.recordno=table2.recordno
table1
recordno
是主鍵。 我正在使用MS-Access數據庫。
您可以使用以下任何一種聯接:
JOIN:當兩個表中至少有一個匹配項時,返回行,
左聯接:即使左表中沒有匹配項,也返回左表中的所有行,
RIGHT JOIN:即使左側表格中沒有匹配項,也返回右側表格中的所有行,
FULL JOIN:當其中一張表匹配時返回行
在您的情況下:
SELECT table1.serialno,table1.recordno, table2.issueid
FROM table1
INNER JOIN table2
ON table1.recordno=table2.recordno
ORDER BY table1.serialno
SELECT table1.serialno,table1.recordno,table2.issueid
FROM table1 LEFT OUTER JOIN table2
ON table1.recordno=table2.recordno
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.