我有这个问题:
Select
p.Id, p.Nazwa
From
tbProjekt p
Where
EXISTS (select UP.*
from tbUserProject UP
where UP.ProjectId = p.Id And UP.UserId = 1)
我想选择其他列UP.IsFullAccessso
,因此请将第一行更改为此列:
Select
p.Id, p.Nazwa, UP.IsFullAccess
但是我收到了错误:
多部分标识符" UP.IsFullAccess"无法受约束。
答案 0 :(得分:1)
您需要在主查询中加入tbUserProject:
Len()
答案 1 :(得分:1)
UP仅存在于EXISTS子查询中,无法从主查询中访问。您可以改为使用JOIN
:
SELECT
p.Id,
p.Nazwa,
UP.IsFullAccess
FROM tbProjekt p
JOIN tbUserProject UP
ON UP.ProjectId = p.Id
AND UP.UserId = 1
如果tbUserProject
表中有多个匹配记录,则主要区别在于重复的可能性。
答案 2 :(得分:0)
如果你需要来自tbProject的唯一值,并且tbUserProject中有一个项目有一个值,一个用户使用它:
SELECT
p.Id,
p.Nazwa,
UP.IsFullAccess
FROM tbProjekt p
INNER JOIN
(
select ProjectId, MAX(IsFullAccess) as IsFullAccess from tbUserProject UP where UP.UserId = 1
group by ProjectId
) UP ON UP.ProjectId = p.Id