我正在尝试在两个liferay表上执行右外连接 - users_
和expandovalue
- 来获取结果集。
当我对所有用户进行以下查询时,我得到了理想的结果。
SELECT USER_.FIRSTNAME
, USER_.LASTNAME
, USER_.EMAILADDRESS
, USER_.JOBTITLE
, expandovalue.data_
from expandovalue
right outer join
user_ on expandovalue.classpk = user_.userid
and expandovalue.columnid =35695;
当尝试对一组用户(用户组的一部分)执行相同操作时,它会出错。查询如下:
SELECT USER_.FIRSTNAME
, USER_.LASTNAME
, USER_.EMAILADDRESS
, USER_.JOBTITLE
, expandovalue.data_
from expandovalue
right outer join
user_ on expandovalue.classpk
in (select userid
from user_
where userid
in ( select userid
from users_usergroups
where usergroupid = 40073
) and status =0) = user_.userid in
(select userid
from user_
where userid
in ( select userid
from users_usergroups
where usergroupid = 40073
)
and status =0
) and expandovalue.columnid =35695
这是子查询,它给出了特定用户组中userid
个人。
(select userid
from user_
where userid in
( select userid
from users_usergroups
where usergroupid = 40073)
and status =0
)
我的方向是否完全错误?请指教。
答案 0 :(得分:1)
尝试此查询:
SELECT USER_.FIRSTNAME,
USER_.LASTNAME,
USER_.EMAILADDRESS,
USER_.JOBTITLE,
expandovalue.data_
from expandovalue
right outer join user_
on expandovalue.classpk IN
(select userid
from user_
where userid in (select userid
from users_usergroups
where usergroupid = 40073) and
status = 0) AND
user_.userid in (select userid
from user_
where userid in (select userid
from users_usergroups
where usergroupid = 40073) AND
status =0) AND
expandovalue.columnid = 35695
第一个子查询结束后缺少“AND”。