也许这个问题是重复的。这里的情况有所不同,这就是我提出问题的原因..
来自表m_groups和m_group_admin
select m_groups.GROUP_CREATOR_ID as GROUP_ADMIN
from m_groups where m_groups.GROUP_ID='6'
union
select m_group_admin.GROUP_ADMIN from m_group_admin
where m_group_admin .GROUP_ID='6';
上面的查询返回一个像
这样的列| GROUP_ADMIN |
---------------
4
8
2
我需要来自表m_user_info的用户ID,名字,姓氏(m_user_info.USER_ID,m_user_info.FIRST_NAME,m_user_info.LAST_NAME)以获取上述输出
我需要这样的输出
| USER_ID | |FIRST_NAME| |LAST_NAME |
----------- ------------- ------------
4 ferdous wahid
8 sumon sumon
2 rahul paul
答案 0 :(得分:2)
试试这个:
SELECT USER_ID,FIRST_NAME,LAST_NAME
FROM m_user_info
WHERE USER_ID IN
(select m_groups.GROUP_CREATOR_ID as GROUP_ADMIN
from m_groups where m_groups.GROUP_ID='6'
union
select m_group_admin.GROUP_ADMIN from m_group_admin
where m_group_admin .GROUP_ID='6';)
<强>解释强>
它将从用户表中选择USER_ID,FIRST_NAME和LAST_NAME以及您拥有的ID。