简体   繁体   English

获取具有一列的一个表的所有列,该列必须从与其数据对应的另一个表派生数据

[英]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.

相关问题 更新所有表记录及其来自另一个表的相应数据 - Updating all table Records with with its corresponding data from another table 将数据从一个 sql 表复制到另一个具有较少列数和不同列的表 - copy data from one sql table to another having less number of columns and a different column 从一个表中获取不在另一个表中的所有数据 MySQL - Get all data from one table that's not in another table MySQL 如何从一个表中获取所有列,而从另一张表中仅获取具有ID的一列? -MySQL - How to get all columns from one table and only one column from another table with ID ? - MySql 从一个表中选择多个列,从另一个表中获取相应的详细信息并将它们插入到另一个表中 - Select multiple columns from one table, get corresponding details from another table and insert these to another table 将列数据从一个表复制到另一个表 - Copy columns data from one table to another 无法使用来自另一个的相应数据正确更新一个MYSQL表 - Failing to properly update one MYSQL table with corresponding data from another 一个表数据作为另一表列中的列标题 - One Table Data as Column Headings in Another table Columns 我需要将数据从2列合并到另一列。 然后将添加的列的所有行合并到另一张表的一个单元格中 - I need to merge data from 2 columns to another column. And then merge all rows of that added column into one cell in another table 将列数据从一个表复制到另一个表 - Copy column data from one table to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM