0

我想从 3 个表中选择值,我为此使用内连接,我正在使用以下查询

  SELECT 
    UserDetail.UserId 'userId', 
    FirstName  'name',  
    Name 'role' 
    FROM UserDetail as ud 
       inner join UserRole as ur ON ud.UserId = ur.UserId 
       inner join [Role] as r ON r.RoleId=ur.RoleId 
       WHERE Username = @username and [Password] =@password 

它向我显示以下错误:无法绑定多部分标识符 UserId(UserDetail.UserId)。谁能告诉我我做错了什么。谢谢

4

2 回答 2

1

替换UserDetail.UserIdud.UserId。如果您UserDetail as ud在子句中使用别名 ( ),FROM您也必须在其他任何地方使用相同的别名。

于 2013-07-27T10:51:52.900 回答
0

替换你UserDetail.UserIdud.UserId

IE:

SELECT 
    ud.UserId 'userId', 
    FirstName  'name',  
    Name 'role' 
    FROM UserDetail as ud 
       inner join UserRole as ur ON ud.UserId = ur.UserId 
       inner join [Role] as r ON r.RoleId=ur.RoleId 
       WHERE Username = @username and [Password] =@password 
于 2013-07-27T10:53:22.503 回答