Mysql - join multiple tables based on column

Perhaps this question is repeated. here the situation is different, so I asked a question.

from table m_groups and 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'; 

the above query returns a column of type

 | GROUP_ADMIN | --------------- 4 8 2 

I need the user ID, first name, last name (m_user_info.USER_ID, m_user_info.FIRST_NAME, m_user_info.LAST_NAME) from the m_user_info table for the above outputs

I need a conclusion like this

  | USER_ID | |FIRST_NAME| |LAST_NAME | ----------- ------------- ------------ 4 ferdous wahid 8 sumon sumon 2 rahul paul 
+6
source share
1 answer

Try the following:

 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';) 

Explanation:

He will select USER_ID, FIRST_NAME and LAST_NAME from the user table with the identifiers that you have.

+2
source

All Articles