[英]Updating all table Records with with its corresponding data from another table
[英]Get all Columns of One table having one column which has to derive data from another table corresponding to its data
考慮一張桌子
PRODUCTSTABLE
product_id | product_name | product_country
1 | ABC | 1
2 | DEF | 3
3 | ASD | 2
4 | JGH | 3
5 | WER | 2
國家桌
country_id | country_name
1 | Japan
2 | China
3 | Uganda
4 | France
5 | United States
我想得到像這個查詢會產生的結果
SELECT * FROM PRODUCTSTABLE;
唯一的區別在於第三列'product_country',而不是從第二個表引用的相應國家名稱必須到來。
謝謝。
您需要使用INNER JOIN
連接兩個表。
SELECT a.product_id,
a.product_name,
b.country_name
FROM products a
INNER JOIN country b
ON a.product_country = b.country_ID
要進一步了解聯接,請訪問以下鏈接:
關於什么:
SELECT
A.Product_ID, A.Product_Name, B.Country_Name
FROM PRODUCTSTABLE A
LEFT JOIN Country_Table B on A.Product_Country = B.Country_ID
試試這篇文章: http : //en.wikipedia.org/wiki/Join_(SQL)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.