2013-10-16 21 views
0

我有三個表,即user,roles,performer_owner。我寫了下面的查詢,提取誰擁有角色6(即表演者)的用戶使用sql並在結果中輸出兩個不同表中的值

SELECT * FROM `users` WHERE uid in (select uid from `users_roles` where rid= 6) 

現在如果我用上面的SQL查詢我會在用戶表中的所有列。與來自第三張表performer_owner的我一樣,我想要一個名爲entity_id的列。 entity_id是所有者的ID。表演者的ID爲field_performer_owner_id,我將以uid的形式從上述sql查詢中獲取數據。我該怎麼做呢?

回答

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);   
相關問題