[英]Get all Columns of One table having one column which has to derive data from another table corresponding to its data
Consider a table 考虑一张桌子
PRODUCTSTABLE PRODUCTSTABLE
product_id | product_name | product_country
1 | ABC | 1
2 | DEF | 3
3 | ASD | 2
4 | JGH | 3
5 | WER | 2
COUNTRY TABLE 国家桌
country_id | country_name
1 | Japan
2 | China
3 | Uganda
4 | France
5 | United States
I want to get results like as this query would produce 我想得到像这个查询会产生的结果
SELECT * FROM PRODUCTSTABLE;
The only difference would be in the third column 'product_country', instead of number respective Country name referenced from the second table must come. 唯一的区别在于第三列'product_country',而不是从第二个表引用的相应国家名称必须到来。
Thank you. 谢谢。
You need to join both tables using INNER JOIN
. 您需要使用
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
To further gain more knowledge about joins, visit the link below: 要进一步了解联接,请访问以下链接:
What about: 关于什么:
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
try this article: http://en.wikipedia.org/wiki/Join_(SQL) 试试这篇文章: http : //en.wikipedia.org/wiki/Join_(SQL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.