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

吃可爱长大的小学妹 提交于 2021-02-08 06:59:24

问题


How to get values for same column name from two different tables in SQL?

column name is emp_id loacated in these two tables: company,employee.


回答1:


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



回答2:


Use this to get the results:

company.emp_id, employee.emp_id



回答3:


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



回答4:


Just put the name of the table before the name of the colomn with a "." between, like:

SELECT company.emp_id, employe.emp_id


来源:https://stackoverflow.com/questions/7513669/how-to-get-values-for-same-column-name-from-two-different-tables-in-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!