SQL inner JOIN & outer JOIN 內部連接與外部連接

  • 0
outer join: 想要列出一個表格中每一筆的資料, 無論它的值在另一個表格中有沒有出現



inner JOIN (left join)
SELECT A1.region_name REGION, SUM(A2.Sales) SALES
FROM Geography A1, Store_Information A2
WHERE A1.store_name = A2.store_name
GROUP BY A1.region_name



REGIONSALES
East$700
West$2050


outer JOIN (right join)
SELECT A1.store_name, SUM(A2.Sales) SALES
FROM Georgraphy A1, Store_Information A2
WHERE A1.store_name = A2.store_name (+)
GROUP BY A1.store_name


store_nameSALES
Boston$700
New York
Los Angeles$1800
San Diego$250

沒有留言 :

張貼留言