SQL内部联接查询返回两个相同的列 [英] SQL inner join query returns two identical columns

查看:51
本文介绍了SQL内部联接查询返回两个相同的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下SQL查询:

Let's say I have the following SQL query:

SELECT *
FROM employee 
INNER JOIN department ON employee.EmpID = department.EmpID

我想问一下,为什么要得到两个 EmpID 列,以及如何才能只获得其中的一个,最好是第一列.

I wanted to ask, why I am getting two EmpID columns, and how can I get only one of those, preferably the first.

我正在使用SQL Server

I'm using SQL server

推荐答案

SELECT employee.EmpID, employee.name, ...
FROM employee 
INNER JOIN department ON employee.EmpID=department.EmpID

要精确并指定所需的列,而不要使用astrisk选择所有列.

Be precise and specify which columns you need instead of using the astrisk to select all columns.

这篇关于SQL内部联接查询返回两个相同的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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