开发者

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

开发者 https://www.devze.com 2023-04-06 12:13 出处:网络
How to get values for same column name from two different tables in SQL? column name is emp_id loacated in these two 开发者_JAVA百科tables: company,employee.If you want data in seperate columns from

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

column name is emp_id loacated in these two 开发者_JAVA百科tables: company,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


Use this to get the results:

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


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

SELECT company.emp_id, employe.emp_id
0

精彩评论

暂无评论...
验证码 换一张
取 消