I am working in a group and group membership functionality
Tables relevant are:
usuarios (id, first_name, last_name, ...)
groups (id, name, .. , id_user )
group_members (id, id_group, id_user)
With this Design i need to get the creator from the groups table (groups.id_user is the creator) and the members from the group_members (group_members.id_usuario)
Wich for now I have only been able to achieve with 2 querys:
/* Retrieve members */
$q = 'SELECT usuarios.id as uid, usuarios.avatar, usuarios.first_name,usuarios.last_name
FROM usuarios LEFT JOIN group_members ON usuarios.id = group_members.id_user
WHERE group_members.id_group = '.$this->id.'';
$r = cache_query($q,'',10);
/* Retrive creator */
$q2 = 'SELECT usuarios.id as uid, usuarios.avatar, usuarios.first_name,usuarios.last_name
FROM usuarios LEFT JOIN groups ON usuarios.id = groups.id_user
WHERE groups.id = '.$this->id;
$r2 = cache_query($q2,'',10);
Is there a way to achieve it with one single query? (i was thinking also just to insert the creator as a member and only use first query)