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

查看:62
本文介绍了如何从SQL中的两个不同表中获取相同列名的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

列名是位于这两个表中的emp_id:company,employee.

column name is emp_id loacated in these two 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

这篇关于如何从SQL中的两个不同表中获取相同列名的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆