简体   繁体   English

如何从SQL中的两个不同表中获取相同列名的值

[英]how to get values for same column name from two different tables in SQL

How to get values for same column name from two different tables in SQL?如何从 SQL 中的两个不同表中获取相同列名的值?

column name is emp_id loacated in these two tables: company,employee .列名是位于这两个表中的emp_idcompany,employee

If you want data in seperate columns from two tables then try :如果您想要来自两个表的单独列中的数据,请尝试:

SELECT c.emp_id, emp.emp_id 
FROM company c
INNER JOIN employee emp on c.company_id = emp.company_id 

If you want to merge both columns data then use this :如果要合并两列数据,请使用以下命令:

SELECT emp_id FROM company
UNION
SELECT emp_id FROM employee

Just put the name of the table before the name of the colomn with a "."只需将表格名称放在带有“.”的列名称之前。 between, like:之间,例如:

SELECT company.emp_id, employe.emp_id

使用它来获得结果:

company.emp_id, employee.emp_id

You can do what you are asking, something like the example below, but if you provide a sample query, it would help...您可以按照您的要求执行操作,类似于下面的示例,但是如果您提供示例查询,它会有所帮助...

select emp.emp_id,company.emp_id
from company
join employee emp on emp.company_id=company_company_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM