我有三个表,即user,roles,performer_owner。我编写了以下查询来提取具有角色6(即执行者)
的用户SELECT * FROM `users` WHERE uid in (select uid from `users_roles` where rid= 6 )
如果我使用上面的sql查询,现在我将获取users表中的所有列。与第三个表performer_owner中的那个一起,我想要一个名为entity_id
的列。 entity_id
是所有者的ID。表达者的id是field_performer_owner_id
,我将以uid
的形式从上面的sql查询中获取数据。我该怎么做?
答案 0 :(得分:0)
加入,
select
u.*,
po.entity_id
from `users` u
join `performer_owner` po on po.field_performer_owner_id = u.id
where u.uid in (select uid from `users_roles` where rid= 6);