为表多次指定了第 xxx 列

The column xxx was specified multiple times for table(为表多次指定了第 xxx 列)
本文介绍了为表多次指定了第 xxx 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使 db2 简单查询适应 SQL SERVER.此查询在 db2 上运行良好

I am trying to adapt a db2 simple query to SQL SERVER. This query is working fine on db2

select * 
from pb_console.users u 
join ( 
     select * from pb_console.users_user_role j join  
     pb_console.users_roles r on j.role_id = r.role_id) as jj 
on jj.user_id = u.user_id

在 sql server 上失败并出现错误:

on sql server it fails with error:

The column 'ROLE_ID' was specified multiple times for 'jj'

我已尝试将角色 _id 从联接的左表中删除为:

I have tried removing role _id from the left table of the join as:

select * from pb_console.users u join ( 
    select user_id, role_rif from 
    pb_console.users_user_role j join (select role_id, role_name from 
pb_console.users_roles) r 
on 
j.role_id = r.role_id) as jj on jj.user_id = u.user_id

但导致.

The column 'role_id' was specified multiple times for 'jj'.

我也尝试为第一个 role_id 使用不同的别名,但没有成功.

I have also tried using a different alias for the first role_id, with no success.

我该如何解决这个问题?

How can I fix this?

推荐答案

由于 ColumnNameROLE_ID 存在于两个表 pb_console.users_user_role &pb_console.users_roles 所以尝试指定只需要的列,如下所示

The error is raised because the ColumnNameROLE_ID is present in both the table pb_console.users_user_role & pb_console.users_roles so try to specify the columns that are only required as below

SELECT * 
FROM pb_console.users u 
join ( 
     SELECT J.RoleID,J.User_ID FROM pb_console.users_user_role j 
     JOIN pb_console.users_roles r ON j.role_id = r.role_id) AS jj 
on jj.user_id = u.user_id

这篇关于为表多次指定了第 xxx 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)