加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 具有内部Join的重复列

发布时间:2020-12-12 16:24:04 所属栏目:MsSql教程 来源:网络整理
导读:SELECT dealing_record.*,shares.*,transaction_type.*FROM shares INNER JOIN shares ON shares.share_ID = dealing_record.share_id INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id; 上面的S
SELECT 
    dealing_record.*,shares.*,transaction_type.*
FROM 
    shares 
    INNER JOIN shares ON shares.share_ID = dealing_record.share_id
    INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id;

上面的SQL代码产生了所需的输出,但有几个重复的列.此外,列标题显示不完整.当我改变了

linesize 100

标题显示但数据显示重叠

我已经检查了类似的问题,但我似乎没有得到如何解决这个问题.

解决方法

你有重复的列,因为,你要向SQL引擎询问他们将显示相同数据的列(使用SELECT dealing_record.*等等),然后重复.

例如,transaction_type.transaction_type_id列和dealing_record.transaction_type_id列将具有匹配的行(否则您将看不到任何带有INNER JOIN的内容),您将看到这些重复项.

如果你想避免这个问题,或者至少要减少结果中重复的风险,那就改善你的查询,只使用你真正需要的列,就像@ConradFrix已经说过的那样.一个例子是这样的:

SELECT 
    dealing_record.Name,shares.ID,shares.Name,transaction_type.Name,transaction_type.ID
FROM 
    shares 
    INNER JOIN shares ON shares.share_ID = dealing_record.share_id
    INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读