问题
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